-
Notifications
You must be signed in to change notification settings - Fork 14
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
Check if parameter is number before Number.parse #191
Conversation
Signed-off-by: Zabil Cheriya Maliackal <zabilcm@gmail.com>
c12eb22
to
918d7e1
Compare
@BugDiver not sure if this is the best way to fix it. Do take a look. |
const num = Number.parseFloat(value); | ||
return Number.isNaN(num) ? undefined : num; | ||
const trimmedValue = value.trim(); | ||
if (/^-?\d+(\.\d+)?$/.test(trimmedValue)) { |
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.
I thought of using a regex but wanted to avoid it because it seemed overkill, but I'm afraid we don't have a choice.
I came up during my investigations with this regex: /^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/
(thanks ChatGPT) to handle extreme case where users would use exponential notations (e.g. 2e-32
). Seems unlikely, but...well better safe than sorry 😄
What if Gauge allowed the "special parameter" notation to specify a plain string like <string:0123456>
and then it would bypass this? 🤔
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.
What if Gauge allowed the "special parameter" notation to specify a plain string like string:0123456 and then it would bypass this?
Thanks for the suggestion! The idea of using a special parameter like <string:0123456>
makes sense. However, it's best to keep Gauge specs as readable and close to markdown as possible. This is to have that clear separation and make the reports readable to people who are not that technical.
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.
@anthony-legay pushed a simpler approach refer 910e614
Is there a way you can test this locally?
Signed-off-by: Zabil Cheriya Maliackal <zabilcm@gmail.com>
Signed-off-by: Chad Wilson <chadw@thoughtworks.com>
8c52256
to
c880f1a
Compare
@zabil Thank you for contributing to gauge-ts. Your pull request has been labeled as a release candidate 🎉🎉. Merging this PR will trigger a release. Please bump up the version as part of this PR.Instructions to bump the version can found at CONTRIBUTING.md If the CONTRIBUTING.md file does not exist or does not include instructions about bumping up the version, please looks previous commits in git history to see what changes need to be done. |
Fixed the artifact upload/download. Otherwise LGTM |
Signed-off-by: Chad Wilson <chadw@thoughtworks.com>
Thanks! @chadlwilson |
Sorry, I'm coming after the party, but this does not actually fix the issue when a value like "0123456" (such as a product id, or serial number) is used as a param and we want it to remains a string. |
Ah shoot. |
Fixes #190 #187