Skip to content

Commit bbf17a8

Browse files
committed
Verify plugin name prefixes. Fixes jquery-archive#23.
1 parent ac29e22 commit bbf17a8

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/service.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extend( Repo.prototype, {
4949
});
5050
},
5151

52-
validatePackageJson: function( package, version ) {
52+
validatePackageJson: function( package, version, prefix ) {
5353
var errors = [];
5454

5555
/** required fields **/
@@ -59,8 +59,22 @@ extend( Repo.prototype, {
5959
errors.push( "Missing required field: name." );
6060
} else if ( typeof package.name !== "string" ) {
6161
errors.push( "Invalid data type for name; must be a string." );
62-
} else if ( !/^jquery\./.test( package.name ) ) {
63-
errors.push( "Name must start with 'jquery.'." );
62+
}
63+
if ( prefix ) {
64+
if ( package.name.indexOf( prefix ) !== 0 ) {
65+
errors.push( "Name must start with '" + prefix + "'." );
66+
}
67+
} else {
68+
if ( package.name.indexOf( "jquery." ) !== 0 ) {
69+
errors.push( "Name must start with 'jquery.'." );
70+
} else {
71+
Object.keys( suites ).forEach(function( repoId ) {
72+
var prefix = suites[ repoId ];
73+
if ( package.name.indexOf( prefix ) === 0 ) {
74+
errors.push( "Name must not start with '" + prefix + "'." );
75+
}
76+
});
77+
}
6478
}
6579

6680
if ( !package.version ) {
@@ -341,7 +355,7 @@ extend( Repo.prototype, {
341355
}
342356

343357
for ( var i = 0, l = packages.length; i < l; i++ ) {
344-
if ( repo.validatePackageJson( packages[ i ], tag ).length ) {
358+
if ( repo.validatePackageJson( packages[ i ], tag, suites[ repo.id ] ).length ) {
345359
return fn( null, null );
346360
}
347361
mappedPackages[ files[ i ] ] = packages[ i ];

0 commit comments

Comments
 (0)