fix: correct flags regex to match server and docs#147
fix: correct flags regex to match server and docs#147drazisil-codecov merged 12 commits intocodecov:masterfrom drazisil:patch-1
Conversation
Isn't that what `const mask = /^[\w/.,-]+$/` is doing though?
Codecov Report
@@ Coverage Diff @@
## master #147 +/- ##
==========================================
- Coverage 91.57% 91.39% -0.19%
==========================================
Files 15 15
Lines 546 546
Branches 105 105
==========================================
- Hits 500 499 -1
Misses 20 20
- Partials 26 27 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
|
What is a flag? What should it be validated for? It seems like this is early to validate for anything other than that flags are of type It might be best to use a command-line parsing library for this functionality. Even with the addition of periods to the regular expression, validation would fail on other seemingly “valid” (from the perspective of them being genuine) flags. |
A "flag" in this context is a feature of Codecov https://docs.codecov.com/docs/flags It's being validated because not all strings are accepted and it's preferred to stop at the upload, rather then at a server error. |
Oh, I see. Thanks for the link. Should the regex be changed to the snippet from the documentation? |
Correct regex is `^[\w\.\-]+${1,45}`, docs have also been updated.
Indeed. Turns out the docs were incorrect as well. Now they both match the server :) |
|
Ok, @codecov/open-source . This is ready for review and merge. Finally. |
| @@ -9,7 +9,7 @@ function validateURL(url) { | |||
| } | |||
|
|
|||
| function validateFlags(flags) { | |||
There was a problem hiding this comment.
Should this be renamed to validateFlag (singular) since it validates one flag?
There was a problem hiding this comment.
Probably , but that's scope creep imo.
src/helpers/validate.js
Outdated
|
|
||
| function validateFlags(flags) { | ||
| const mask = /^(?!-)[\w,-]+$/ | ||
| const mask = /^[\w,\.,\-]{1,45}$/ |
There was a problem hiding this comment.
There is benefit in moving this regex outside.
Currently, every invocation of validateFlags will instantiate a unique regular expression instance which will promptly be destroyed (and never reused) after the function returns. The optimization here is to simply instantiate one regular expression but share it among every invocation of the function. This is common practice with regular expressions in JavaScript because complex patterns can be (relatively) expensive to compile.
There was a problem hiding this comment.
Is this intended to match commas?
There was a problem hiding this comment.
| const mask = /^[\w,\.,\-]{1,45}$/ | |
| const mask = /^[\w\.\-]{1,45}$/ |
fix: do not match commas
There was a problem hiding this comment.
Currently, every invocation of validateFlags will instantiate a unique regular expression instance which will promptly be destroyed (and never reused) after the function returns
I don't follow. Except in tests, this regex should generally only be used once per execution
|
The boundaries of the regular expression should be tested; namely:
|
It appears that the docs are still somewhat incorrect:
|
* chore(deps): update dependency eslint to v7.29.0 (#150) * chore(deps): update alpine docker tag to v3.14.0 (#144) * chore(deps): update dependency jest to v27.0.5 (#156) * fix: correct flags regex to match server and docs (#147) * refactor: all exits moved to cli, throw as needed (#157) * chore: change headers to standard (#158) Co-authored-by: Renovate Bot <[email protected]> Co-authored-by: Drazi Crendraven <[email protected]>
fixes #146