Skip to content

chore(clients): strictly parse booleans #2514

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

Merged
merged 7 commits into from
Jun 25, 2021

Conversation

JordonPhillips
Copy link
Member

Issue

n/a

Description

This updates boolean parsing to be more strict. Previously there was a simple === "true" check, which allowed malformed requests to be accepted.

Testing

Tests were added, including tests covering common alternatives for boolean string representations.

Additional context

This is part of a pass through to make sure the types we're receiving are actually the types we expect. There will likely be more PRs on this theme.

See smithy-lang/smithy-typescript#364 for the other half of this.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

This adds a helper for parsing booleans from strings. Previously a
simple `=== "true"` check was being performed, but this implies that
anything that isn't that particular string is false.
Co-authored-by: Trivikram Kamat <[email protected]>
@JordonPhillips JordonPhillips requested a review from trivikr June 25, 2021 13:49
@trivikr
Copy link
Member

trivikr commented Jun 25, 2021

CI Error:

lerna ERR! yarn run build exited 2 in '@aws-sdk/aws-restjson'
--
429 | lerna ERR! yarn run build stdout:
430 | $ yarn build:cjs && yarn build:es
431 | $ tsc -p tsconfig.json
432 | protocols/Aws_restJson1.ts(2561,46): error TS2345: Argument of type 'string' is not assignable to parameter of type '"true" \| "false"'.
433 | protocols/Aws_restJson1.ts(2564,47): error TS2345: Argument of type 'string' is not assignable to parameter of type '"true" \| "false"'.
434 | protocols/Aws_restJson1.ts(2580,39): error TS2345: Argument of type 'string' is not assignable to parameter of type '"true" \| "false"'.
435 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
436 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@JordonPhillips JordonPhillips requested a review from trivikr June 25, 2021 15:10
@JordonPhillips JordonPhillips changed the title Parse boolean chore: strictly parse booleans Jun 25, 2021
@trivikr trivikr changed the title chore: strictly parse booleans chore(clients): strictly parse booleans Jun 25, 2021
@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (main@608e606). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2514   +/-   ##
=======================================
  Coverage        ?   59.55%           
=======================================
  Files           ?      495           
  Lines           ?    26402           
  Branches        ?     6272           
=======================================
  Hits            ?    15723           
  Misses          ?    10679           
  Partials        ?        0           

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 608e606...346d921. Read the comment docs.

case "false":
return false;
default:
throw new Error(`Unable to parse boolean value "${value}"`);
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 TypeError like the expect methods, or no?

Copy link
Member Author

Choose a reason for hiding this comment

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

Technically it's not a type error, it's a parse error. We can always change it if necessary

Copy link
Contributor

Choose a reason for hiding this comment

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

As long as at the end of the day we can generate a meaningful SerializationException for callers (when SerializationException has messages... whoops), that's all I care about. Reading messages from bare Error types is dangerous, could leak something unintended.

@JordonPhillips JordonPhillips merged commit 4e4c1a0 into aws:main Jun 25, 2021
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants