forked from forgejo/forgejo
Fix NPM packages name validation (#26595)
- Added new tests to cover corner cases - Replace existing regex with new one Closes #26551 --- As @silverwind suggested, I started from [validate-npm-package-name](https://github.com/npm/validate-npm-package-name), but found this solution too complicated. Then I tried to fix existing regex myself, but thought, that exclude all restricted symbols is harder, than set only allowed symbols. Then I search a bit more and found [package-name-regex](https://github.com/dword-design/package-name-regex) and regex from it works for all new test cases. Let me know, if more information or help with this PR is needed.
This commit is contained in:
parent
ead52dd96c
commit
84d05516dc
2 changed files with 19 additions and 1 deletions
|
@ -34,7 +34,7 @@ var (
|
|||
ErrInvalidIntegrity = util.NewInvalidArgumentErrorf("failed to validate integrity")
|
||||
)
|
||||
|
||||
var nameMatch = regexp.MustCompile(`\A((@[^\s\/~'!\(\)\*]+?)[\/])?([^_.][^\s\/~'!\(\)\*]+)\z`)
|
||||
var nameMatch = regexp.MustCompile(`^(@[a-z0-9-][a-z0-9-._]*/)?[a-z0-9-][a-z0-9-._]*$`)
|
||||
|
||||
// Package represents a npm package
|
||||
type Package struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue