Skip to content
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

Merged
merged 12 commits into from
Jun 22, 2021
Merged

fix: correct flags regex to match server and docs #147

merged 12 commits into from
Jun 22, 2021

Conversation

drazisil
Copy link
Contributor

fixes #146

@drazisil drazisil requested a review from a team as a code owner June 18, 2021 00:02
Isn't that what `const mask = /^[\w/.,-]+$/` is doing though?
@drazisil drazisil marked this pull request as draft June 18, 2021 00:10
@drazisil drazisil marked this pull request as ready for review June 18, 2021 00:12
@drazisil drazisil changed the title Flags with periods Support periods in flags Jun 18, 2021
@codecov
Copy link

codecov bot commented Jun 18, 2021

Codecov Report

Merging #147 (a5f9338) into master (5856d15) will decrease coverage by 0.18%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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     
Flag Coverage Δ
alpine 91.39% <100.00%> (-0.19%) ⬇️
linux 91.39% <100.00%> (-0.19%) ⬇️
linux-without-git ∅ <ø> (∅)
macos 91.39% <100.00%> (-0.19%) ⬇️
macos-without-git ∅ <ø> (∅)
windows 90.84% <100.00%> (-0.19%) ⬇️
windows-without-git ∅ <ø> (∅)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/helpers/validate.js 100.00% <100.00%> (ø)
src/ci_providers/provider_circleci.js 90.32% <0.00%> (-3.23%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5856d15...a5f9338. Read the comment docs.

@RA80533
Copy link
Contributor

RA80533 commented Jun 18, 2021

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 string.

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.

@drazisil
Copy link
Contributor Author

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 string.

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.

@RA80533
Copy link
Contributor

RA80533 commented Jun 18, 2021

Only lowercase, alphanumeric values are accepted. ^[a-z0-9_\.\-]{1,45}$

Oh, I see. Thanks for the link.

Should the regex be changed to the snippet from the documentation?

@drazisil
Copy link
Contributor Author

Should the regex be changed to the snippet from the documentation?

Indeed. Turns out the docs were incorrect as well. Now they both match the server :)

@drazisil drazisil changed the title Support periods in flags fix: correct flags regex to match server and docs Jun 19, 2021
src/helpers/validate.js Outdated Show resolved Hide resolved
@drazisil
Copy link
Contributor Author

Ok, @codecov/open-source . This is ready for review and merge. Finally.

@@ -9,7 +9,7 @@ function validateURL(url) {
}

function validateFlags(flags) {
Copy link
Contributor

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?

Copy link
Contributor

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.

@@ -9,7 +9,7 @@ function validateURL(url) {
}

function validateFlags(flags) {
const mask = /^(?!-)[\w,-]+$/
const mask = /^[\w,\.,\-]{1,45}$/
Copy link
Contributor

@RA80533 RA80533 Jun 21, 2021

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.

Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const mask = /^[\w,\.,\-]{1,45}$/
const mask = /^[\w\.\-]{1,45}$/

fix: do not match commas

Copy link
Contributor

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

@RA80533
Copy link
Contributor

RA80533 commented Jun 21, 2021

The boundaries of the regular expression should be tested; namely:

  • Length: (0, 1, 45, 46)
  • Characters: (uppercase and lowercase alphabetical; numeral; underline; dash; period; comma)

@RA80533
Copy link
Contributor

RA80533 commented Jun 21, 2021

Should the regex be changed to the snippet from the documentation?

Indeed. Turns out the docs were incorrect as well. Now they both match the server :)

It appears that the docs are still somewhat incorrect:

^[\w\.\-]+${1,45}$

+$ should be removed, resulting in:

^[\w\.\-]{1,45}$

@drazisil-codecov drazisil-codecov merged commit 6d2a1ac into codecov:master Jun 22, 2021
drazisil-codecov added a commit that referenced this pull request Jun 23, 2021
* 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>
@drazisil drazisil deleted the patch-1 branch June 25, 2021 14:48
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.

Flags not working when they contain a period
4 participants