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

Safer buildQueryString #94

Merged
merged 4 commits into from
Jan 16, 2020
Merged

Conversation

johnwiseheart
Copy link
Contributor

Before this PR

buildQueryString assumed it would take an object, and then iterated through its keys. However, because in both of its uses it was being passed an any, it was not guaranteed that it is an object. This lead to conjure-client-factory passing params.queryArguments = undefined, which would cause an error.

After this PR

==COMMIT_MSG==
Check that queryArguments is non-null before iterating over keys
==COMMIT_MSG==

@changelog-app
Copy link

changelog-app bot commented Jan 15, 2020

Generate changelog in packages/conjure-client/changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Check that queryArguments is non-null before iterating over keys

Check the box to generate changelog(s)

  • Generate changelog entry

@policy-bot policy-bot bot requested a review from dansanduleac January 15, 2020 23:56
@ferozco
Copy link
Contributor

ferozco commented Jan 16, 2020

Looks like the typings are overly lenient. In practice this doesn't regularly come up since conjure-typescript correctly generates a map.

Since it is technically legal to pass anything as a query param, it doesn't hurt to be defensive

@@ -190,7 +190,11 @@ export class FetchBridge implements IHttpApiBridge {
return path;
}

private buildQueryString(data: { [key: string]: any }) {
private buildQueryString(data: any) {
if (data == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be sufficient since Object.keys() seems to coerce all other types correctly

@ferozco
Copy link
Contributor

ferozco commented Jan 16, 2020

👍

@svc-autorelease
Copy link
Collaborator

The autorelease label is not supported for this repository type. Please merge this PR first and then use the Autorelease UI

1 similar comment
@svc-autorelease
Copy link
Collaborator

The autorelease label is not supported for this repository type. Please merge this PR first and then use the Autorelease UI

Copy link
Contributor

@ferozco ferozco left a comment

Choose a reason for hiding this comment

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

We shouldn't cut a major rev of this repo just to change a typing that only impacts tests. I would prefer to either add a defensive check to ensure the object is not null

@johnwiseheart
Copy link
Contributor Author

Removed break

@ferozco
Copy link
Contributor

ferozco commented Jan 16, 2020

great! thanks for the fix @johnwiseheart

@ferozco
Copy link
Contributor

ferozco commented Jan 16, 2020

looks like changelog-app is confused...

@johnwiseheart
Copy link
Contributor Author

Yeah I think theres something weird going on, don't think https://github.com/palantir/conjure-typescript-runtime/blob/develop/changelog/%40unreleased/pr-82.v2.yml should still be in @unreleased either

@ferozco ferozco merged commit b382246 into palantir:develop Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants