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

Check is value is undefined in appendQueryParams #18621

Merged
merged 5 commits into from
Nov 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions sdk/core/core-client/src/urlHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,11 @@ function calculateQueryParameters(
};
}

function simpleParseQueryParams(queryString: string): Map<string, string | string[]> {
const result: Map<string, string | string[]> = new Map<string, string | string[]>();
function simpleParseQueryParams(queryString: string): Map<string, string | string[] | undefined> {
const result: Map<string, string | string[] | undefined> = new Map<
string,
string | string[] | undefined
>();
if (!queryString || queryString[0] !== "?") {
return result;
}
Expand Down Expand Up @@ -288,11 +291,13 @@ export function appendQueryParams(
for (const [name, value] of combinedParams) {
if (typeof value === "string") {
searchPieces.push(`${name}=${value}`);
} else {
} else if (Array.isArray(value)) {
// QUIRK: If we get an array of values, include multiple key/value pairs
for (const subValue of value) {
searchPieces.push(`${name}=${subValue}`);
}
} else {
searchPieces.push(`${name}=${value}`);
Comment on lines +299 to +300
Copy link
Member

Choose a reason for hiding this comment

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

So this will cause undefined to show up as name=undefined in the query string, which seems to match how URLSearchParams handles this:

image

I'm fine with it, but can we test this change on the service that was impacted by the linked issue before merging?

Copy link
Member

@deyaaeldeen deyaaeldeen Nov 11, 2021

Choose a reason for hiding this comment

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

If the service did not like this, I think we will need to do:

Suggested change
} else {
searchPieces.push(`${name}=${value}`);
} else if (value === undefined) {
searchPieces.push(name);
} else {
searchPieces.push(`${name}=${value}`);

Copy link
Member

Choose a reason for hiding this comment

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

The last else should be unreachable, right?

Copy link
Member

Choose a reason for hiding this comment

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

I think you're right, we could just throw an error there just in case.

Copy link
Member Author

Choose a reason for hiding this comment

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

So this will cause undefined to show up as name=undefined in the query string, which seems to match how URLSearchParams handles this:

image

I'm fine with it, but can we test this change on the service that was impacted by the linked issue before merging?

Yes. I have tested the changes with the actual iothub service that was causing this issue. It works fine. Thanks

}
}

Expand Down