Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: Invalidate special chars #13

Merged
merged 4 commits into from
Feb 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ var validate = module.exports = function(name) {
warnings.push("name can no longer contain capital letters")
}

if (/[~'!()*]/.test(name.split('/').slice(-1)[0])) {
warnings.push('name can no longer contain special characters ("~\'!()*")')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious about the choice of using warn rather than error, I imagine:

  1. on the registry we'll block new publications that cause this warning.
  2. the CLI will log the message but allow the publish.
  3. old packages will continue to be able to be published?

This seems reasonable to me, just refreshing myself with this module.

}

if (encodeURIComponent(name) !== name) {

// Maybe it's a scoped package name, like @user/package
Expand Down
8 changes: 6 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ test("validate-npm-package-name", function (t) {
t.deepEqual(validate("under_score"), {validForNewPackages: true, validForOldPackages: true})
t.deepEqual(validate("period.js"), {validForNewPackages: true, validForOldPackages: true})
t.deepEqual(validate("123numeric"), {validForNewPackages: true, validForOldPackages: true})
t.deepEqual(validate("crazy!"), {validForNewPackages: true, validForOldPackages: true})
t.deepEqual(validate("crazy!"), {validForNewPackages: false, validForOldPackages: true, warnings: [
'name can no longer contain special characters ("~\'!()*")'
]})

// Scoped (npm 2+)

t.deepEqual(validate("@npm/thingy"), {validForNewPackages: true, validForOldPackages: true})
t.deepEqual(validate("@npm-zors/money!time.js"), {validForNewPackages: true, validForOldPackages: true})
t.deepEqual(validate("@npm-zors/money!time.js"), {validForNewPackages: false, validForOldPackages: true, warnings: [
'name can no longer contain special characters ("~\'!()*")'
]})

// Invalid

Expand Down