Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

More accurate package.json name regex #1232

Closed
shravan2x opened this issue Aug 26, 2017 · 2 comments
Closed

More accurate package.json name regex #1232

shravan2x opened this issue Aug 26, 2017 · 2 comments

Comments

@shravan2x
Copy link

shravan2x commented Aug 26, 2017

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 was unable to find the regex in this repo, so please redirect me if such an issue should be posted elsewhere.

I propose that this regex be changed to

^(?=.{1,214}$)(?:@[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.

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

EDIT 1: Improved regex
EDIT 2: Added more tests

@shravan2x shravan2x changed the title Better package.json name regex More accurate package.json name regex Aug 26, 2017
@rosieks
Copy link
Contributor

rosieks commented Aug 26, 2017

This schema comes from https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/package.json, so I suggest to report this issue in that repository

@shravan2x
Copy link
Author

Will do, thank you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants