Allow dash as delimiter in MACs.

This commit is contained in:
baldo 2022-07-22 17:10:39 +02:00
parent 533710a2d4
commit ffc0f13eb8
4 changed files with 9 additions and 8 deletions

View file

@ -32,7 +32,7 @@ function getNormalizedNodeData(reqData: any): CreateOrUpdateNode {
_.each(nodeFields, function (field) { _.each(nodeFields, function (field) {
let value = normalizeString(reqData[field]); let value = normalizeString(reqData[field]);
if (field === 'mac') { if (field === 'mac') {
value = normalizeMac(value); value = normalizeMac(value as MAC);
} }
node[field] = value; node[field] = value;
}); });

View file

@ -1,12 +1,13 @@
import _ from "lodash" import _ from "lodash"
import {MAC} from "../types";
export function normalizeString(str: string): string { export function normalizeString(str: string): string {
return _.isString(str) ? str.trim().replace(/\s+/g, ' ') : str; 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 // 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 = []; const macParts = [];
@ -14,7 +15,7 @@ export function normalizeMac (mac: string): string {
macParts.push(parts[i]); macParts.push(parts[i]);
} }
return macParts.join(':'); return macParts.join(':') as MAC;
} }
export function parseInteger(str: string): number { export function parseInteger(str: string): number {

View file

@ -40,7 +40,7 @@ const CONSTRAINTS = {
}, },
coords: { coords: {
type: 'string', 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 optional: true
}, },
monitoring: { monitoring: {

View file

@ -38,7 +38,7 @@
}, },
mac: { mac: {
type: 'string', 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 optional: false
}, },
coords: { coords: {