Skip to content

Commit

Permalink
Exclude entity prop named Name
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite committed Sep 13, 2023
1 parent a0c83d8 commit ee2f81b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/data/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ const validatePropertyName = (name) => {
// (similar to above dataset name check with some slight differences)
// Check for a match with a valid string
// (?!__) is negative lookahead to check string does not start with double underscore __
// (?!name$)(?!label$) negative lookahead for "name" and "label" specifically
// (?!name$)(?!label$) negative lookahead for "name" and "label" specifically, insensitive to case
// [\p{L}_] valid start character of unicode letter or _ (no :)
// [\p{L}\d\\._-]* more characters from valid starting character set, digits, hyphens, and '.'
// If there's a match, return true (valid)!
// Non-letter unicode characters also not currently allowed
const match = /^(?!__)(?!name$)(?!label$)[\p{L}_][\p{L}\d._-]*$/u.exec(name);
const match = /^(?!__)(?!name$)(?!label$)[\p{L}_][\p{L}\d._-]*$/u.exec(name.toLowerCase());

return (match !== null);
};
Expand Down
6 changes: 6 additions & 0 deletions test/unit/data/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ describe('property name validation', () => {
validatePropertyName('label').should.equal(false);
});

it('should reject name or label in case-insensitive way', () => {
validatePropertyName('Name').should.equal(false);
validatePropertyName('NaMe').should.equal(false);
validatePropertyName('LABEL').should.equal(false);
});

it('should reject name with whitespace at the ends', () => {
validatePropertyName(' bad_whitespace ').should.equal(false);
});
Expand Down

0 comments on commit ee2f81b

Please sign in to comment.