Skip to content

More accurate package.json name regex #331

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

Merged
merged 1 commit into from
Aug 28, 2017

Conversation

shravan2x
Copy link
Contributor

@shravan2x shravan2x commented Aug 26, 2017

This issue was originally posted at aspnet/JavaScriptServices#1232.

As of VS2017, the package.json name field is required to match the regex ^[^A-Z]+$ and have a length not more than 214 characters.

image

I propose that this regex be changed to

^(?:@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$

This regex follows the guidelines at https://docs.npmjs.com/files/package.json better. I have added some simple unit tests for it over at https://regex101.com/r/QgADad/3/tests.

The following lines can also be handled by the regex itself by prepending (?=.{1,214}$), but I have not made this change in case these fields serve other purposes too.

"maxLength": 214,
"minLength": 1

Please let me know if you would like me to clarify the regex in any way. It is much more complex than the existing one, but also more accurate.

Ref:
https://stackoverflow.com/questions/695438/safe-characters-for-friendly-url
https://stackoverflow.com/questions/11197549/regular-expression-limit-string-size

@madskristensen madskristensen merged commit 408486d into SchemaStore:master Aug 28, 2017
@madskristensen
Copy link
Contributor

Brilliant. Thanks 👍

@shravan2x shravan2x deleted the patch-1 branch August 28, 2017 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants