-
Notifications
You must be signed in to change notification settings - Fork 74
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
fix: correct flags regex to match server and docs #147
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be renamed to validateFlag
(singular) since it validates one flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably , but that's scope creep imo.
src/helpers/validate.js
Outdated
@@ -9,7 +9,7 @@ function validateURL(url) { | |||
} | |||
|
|||
function validateFlags(flags) { | |||
const mask = /^(?!-)[\w,-]+$/ | |||
const mask = /^[\w,\.,\-]{1,45}$/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intended to match commas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const mask = /^[\w,\.,\-]{1,45}$/ | |
const mask = /^[\w\.\-]{1,45}$/ |
fix: do not match commas
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <bot@renovateapp.com> Co-authored-by: Drazi Crendraven <drazisil@users.noreply.github.com>
fixes #146