From 3444ac9feb83d2516a1d5875a114ccd5238b2cb4 Mon Sep 17 00:00:00 2001 From: Sam Lee-Lindsay Date: Tue, 23 Jul 2024 17:50:23 +1000 Subject: [PATCH] Fix(SCIMMY.Types.Attribute): allow leading '-' character in attribute names again --- src/lib/types/attribute.js | 2 +- test/lib/types/attribute.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/types/attribute.js b/src/lib/types/attribute.js index 71a4782..309d500 100644 --- a/src/lib/types/attribute.js +++ b/src/lib/types/attribute.js @@ -308,7 +308,7 @@ export class Attribute { constructor(type, name, config = {}, subAttributes = []) { const errorSuffix = `attribute definition '${name}'`; // Check for invalid characters in attribute name - const [, invalidNameChar, invalidNameStart] = /([^-$\w])|(^[^$\w])/g.exec(name) ?? []; + const [, invalidNameChar, invalidNameStart] = /([^-$\w])|(^[^-$\w])/g.exec(name) ?? []; // Make sure name and type are supplied as strings for (let [param, value] of [["type", type], ["name", name]]) if (typeof value !== "string") diff --git a/test/lib/types/attribute.js b/test/lib/types/attribute.js index dfdb362..c219cc6 100644 --- a/test/lib/types/attribute.js +++ b/test/lib/types/attribute.js @@ -73,13 +73,12 @@ describe("SCIMMY.Types.Attribute", () => { ["=", "invalid=name"], [",", "invalid,name"], ["%", "invalid%name"], - ["%", "%invalidName"], - ["-", "-invalidName"] + ["%", "%invalidName"] ]; for (let [char, name] of invalidNames) { assert.throws(() => new Attribute("string", name), - {name: "TypeError", message: `Invalid ${name.startsWith("-") ? "leading character" : "character"} '${char}' in name of attribute definition '${name}'`}, + {name: "TypeError", message: `Invalid character '${char}' in name of attribute definition '${name}'`}, `Attribute instantiated with invalid 'name' argument '${name}'`); } @@ -89,6 +88,7 @@ describe("SCIMMY.Types.Attribute", () => { "valid$name", "_validName", "valid_name", + "-validName", "valid-name", "00validName", "valid00name"