Allow dash as delimiter in MACs.
This commit is contained in:
parent
533710a2d4
commit
ffc0f13eb8
|
@ -32,7 +32,7 @@ function getNormalizedNodeData(reqData: any): CreateOrUpdateNode {
|
|||
_.each(nodeFields, function (field) {
|
||||
let value = normalizeString(reqData[field]);
|
||||
if (field === 'mac') {
|
||||
value = normalizeMac(value);
|
||||
value = normalizeMac(value as MAC);
|
||||
}
|
||||
node[field] = value;
|
||||
});
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import _ from "lodash"
|
||||
import {MAC} from "../types";
|
||||
|
||||
export function normalizeString(str: string): string {
|
||||
return _.isString(str) ? str.trim().replace(/\s+/g, ' ') : str;
|
||||
}
|
||||
|
||||
export function normalizeMac (mac: string): string {
|
||||
export function normalizeMac(mac: MAC): MAC {
|
||||
// parts only contains values at odd indexes
|
||||
const parts = mac.toUpperCase().replace(/:/g, '').split(/([A-F0-9]{2})/);
|
||||
const parts = mac.toUpperCase().replace(/[-:]/g, '').split(/([A-F0-9]{2})/);
|
||||
|
||||
const macParts = [];
|
||||
|
||||
|
@ -14,7 +15,7 @@ export function normalizeMac (mac: string): string {
|
|||
macParts.push(parts[i]);
|
||||
}
|
||||
|
||||
return macParts.join(':');
|
||||
return macParts.join(':') as MAC;
|
||||
}
|
||||
|
||||
export function parseInteger(str: string): number {
|
||||
|
|
|
@ -40,7 +40,7 @@ const CONSTRAINTS = {
|
|||
},
|
||||
coords: {
|
||||
type: 'string',
|
||||
regex: /^(-?[0-9]{1,3}(\.[0-9]{1,15})? -?[0-9]{1,3}(\.[0-9]{1,15})?)$/,
|
||||
regex: /^([a-f0-9]{12}|([a-f0-9]{2}:){5}[a-f0-9]{2}|([a-f0-9]{2}-){5}[a-f0-9]{2})$/i,
|
||||
optional: true
|
||||
},
|
||||
monitoring: {
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
},
|
||||
mac: {
|
||||
type: 'string',
|
||||
regex: /^([a-f0-9]{12}|([a-f0-9]{2}:){5}[a-f0-9]{2})$/i,
|
||||
regex: /^([a-f0-9]{12}|([a-f0-9]{2}:){5}[a-f0-9]{2}|([a-f0-9]{2}-){5}[a-f0-9]{2})$/i,
|
||||
optional: false
|
||||
},
|
||||
coords: {
|
||||
|
|
Loading…
Reference in a new issue