Skip to content

Commit

Permalink
Limit allowed characters in User.name (#88)
Browse files Browse the repository at this point in the history
* Limit Name allowed characters

* bump version
  • Loading branch information
kitfoster authored Jan 10, 2025
1 parent d175500 commit f78f111
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zeit/schemas",
"version": "2.37.0",
"version": "2.38.0",
"description": "All schemas used for validation that are shared between our projects",
"scripts": {
"test": "yarn run lint && best --verbose",
Expand Down
34 changes: 34 additions & 0 deletions test/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,40 @@ exports.test_name_too_long = () => {
);
};

exports.test_name_32_chars = () => {
const isValid = ajv.validate(User, {
name: 'a'.repeat(32)
});
assert.equal(isValid, true);
};

exports.test_name_valid_special_chars = () => {
assert(ajv.validate(User, { name: "John O'Neil" }));
assert(ajv.validate(User, { name: 'Anne-Marie Johnson' }));
assert(ajv.validate(User, { name: 'Dr. J.R. Smith' }));
assert(ajv.validate(User, { name: 'Renée' }));
assert(ajv.validate(User, { name: 'John_Doe' }));
assert(ajv.validate(User, { name: 'John@Vercel' }));
assert(ajv.validate(User, { name: 'John (Jack)' }));
assert(ajv.validate(User, { name: 'Martin, Jr.' }));
assert(ajv.validate(User, { name: 'Åsa' }));
assert(ajv.validate(User, { name: 'Łukasz' }));
assert(ajv.validate(User, { name: 'Ōsaka' }));
assert(ajv.validate(User, { name: '王小明' }));
assert(ajv.validate(User, { name: '山田太郎' }));
assert(ajv.validate(User, { name: 'محمد' }));
assert(ajv.validate(User, { name: 'Dr. 李四@Work' }));
assert(ajv.validate(User, { name: 'Γιάννης' }));
assert(ajv.validate(User, { name: 'Сергей' }));
assert(ajv.validate(User, { name: '123' }));
assert(ajv.validate(User, { name: 'Müller' }));
};

exports.test_name_invalid_special_chars = () => {
assert.equal(ajv.validate(User, { name: '<html>test</html>' }), false);
assert.equal(ajv.validate(User, { name: '![a.png](https://example.com/a.png)' }), false);
};

exports.test_name_valid = () => {
assert(ajv.validate(User, { name: 'Nate' }));
};
Expand Down
3 changes: 2 additions & 1 deletion user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const Username = {
const Name = {
type: 'string',
minLength: 1,
maxLength: 32
maxLength: 32,
pattern: '^[^\\[\\]<>#$!*;]*$'
};

const Email = {
Expand Down

0 comments on commit f78f111

Please sign in to comment.