Skip to content

Commit

Permalink
Make name validation far less strict
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerun committed Apr 4, 2016
1 parent 4793fc0 commit 8e181c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packages/bower-json/lib/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,16 @@ function getIssues(json) {
if (!json.name) {
errors.push('No "name" property set');
} else {
if (!/^[a-zA-Z0-9_][a-zA-Z0-9\.\-_]*$/.test(json.name)) {
errors.push('Name must be lowercase string, with dots, dashes, or @');
if (!/^[a-zA-Z0-9_@][a-zA-Z0-9_@\.\- \/]*$/.test(json.name)) {
errors.push('Name must be lowercase, can contain digits, dots, dashes, "@" or spaces');
}

if (json.name.length > 50) {
warnings.push('The "name" is too long, the limit is 50 characters');
}

if (/[A-Z]/.test(json.name)) {
warnings.push('The "name" must be lowercase');
if (!/^[a-z0-9_][a-z0-9_\.\-]*$/.test(json.name)) {
warnings.push('The "name" is recommended to be lowercase, can contain digits, dots, dashes');
}

if (/^[\.-]/.test(json.name)) {
Expand Down
8 changes: 7 additions & 1 deletion packages/bower-json/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ describe('.parse', function () {
});

describe('.getIssues', function () {
it('should print no errors even for weird package names', function () {
var json = { name: '@gruNt/my dependency' };

expect(bowerJson.getIssues(json).errors).to.be.empty();
});

it('should validate the name length', function () {
var json = { name: 'a_123456789_123456789_123456789_123456789_123456789_z' };

Expand All @@ -284,7 +290,7 @@ describe('.getIssues', function () {
var json = { name: 'gruNt' };

expect(bowerJson.getIssues(json).warnings).to.contain(
'The "name" must be lowercase'
'The "name" is recommended to be lowercase, can contain digits, dots, dashes'
);
});

Expand Down

0 comments on commit 8e181c1

Please sign in to comment.