Check for invalid package names early in the codepath.

We already don't work with packages that contain '.' in the name, this just moves the error up and makes it clearer.
This commit is contained in:
Nick Martin
2013-08-06 15:23:57 -07:00
parent dfd2068d4f
commit e7bb166a02

View File

@@ -175,6 +175,17 @@ _.extend(Library.prototype, {
return self.loadedPackages[name].pkg;
}
// Check for invalid package names.
//
// XXX should we be even stricter and whitelist something like
// /\-_A-Za-z0-9/ instead of blacklisting some special characters?
// What about unicode package names?
if (/[\.\?|'"#<>\(\)]/.test(name)) {
if (throwOnError === false)
return null;
throw new Error("Invalid package name: " + name);
}
var packageDir = self.findPackageDirectory(name);
if (! packageDir) {