Skip to content

Commit

Permalink
Fix(SCIMMY.Types.Attribute): allow leading '-' character in attribute…
Browse files Browse the repository at this point in the history
… names again
  • Loading branch information
sleelin committed Jul 23, 2024
1 parent 679cf5b commit 3444ac9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib/types/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions test/lib/types/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}'`);
}

Expand All @@ -89,6 +88,7 @@ describe("SCIMMY.Types.Attribute", () => {
"valid$name",
"_validName",
"valid_name",
"-validName",
"valid-name",
"00validName",
"valid00name"
Expand Down

0 comments on commit 3444ac9

Please sign in to comment.