Skip to content

Commit

Permalink
fix(core): update github username validation to align with Github val…
Browse files Browse the repository at this point in the history
…idation rules

Closes #144
  • Loading branch information
Justin Dietz authored and tinesoft committed Jan 30, 2018
1 parent 84eafd7 commit 26b0e6f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions __tests__/test-validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ describe('ngx-library:validators', () => {
assert.strictEqual(!validators.validateGithubUsername(), false, 'not passing a value should fail validation');
assert.strictEqual(!validators.validateGithubUsername('My_/_Name'), false, 'not passing a valid value should fail validation');
assert.strictEqual(validators.validateGithubUsername('user007'), true, 'passing a valid value passes validation');
assert.strictEqual(validators.validateGithubUsername('a'.repeat(39)), true, 'passing a 39 char string should pass validation');
assert.strictEqual(validators.validateGithubUsername('user-007'), true, 'passing dash in the middle of a user name should pass validation');
assert.strictEqual(validators.validateGithubUsername('a-b-123'), true, 'passing multiple non repeating dashes should pass validation');
assert.strictEqual(!validators.validateGithubUsername('-user007'), false, 'passing a dash at the beginning of a user name should fail validation');
assert.strictEqual(!validators.validateGithubUsername('user007-'), false, 'passing a dash at the end of a user name should fail validation');
assert.strictEqual(!validators.validateGithubUsername('user--007'), false, 'passing repeating dash should fail validation');
assert.strictEqual(!validators.validateGithubUsername('a'.repeat(40)), false, 'passing a 40 char string should fail validation');
});

it('should validate "githubRepoName"', () => {
Expand Down
2 changes: 1 addition & 1 deletion app/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
},

validateGithubUsername: input => {
return /^[a-zA-Z0-9]+$/.test(input) ? true : 'Your github username cannot contain special characters or a blank space';
return /^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i.test(input) ? true : 'Your github username cannot contain special characters or a blank space';
},

validateGithubRepoName: input => {
Expand Down

0 comments on commit 26b0e6f

Please sign in to comment.