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

[bug] Generate url with nested query params #19809

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
20 changes: 20 additions & 0 deletions packages/ember/tests/routing/router_service_test/urlFor_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ moduleFor(
});
}

['@test RouterService#urlFor returns URL for simple route with nested object as query params'](assert) {
assert.expect(1);

let queryParams = this.buildQueryParams({
filter: {
user: {
name: {
$contains: 'foo',
},
},
},
});

return this.visit('/').then(() => {
let expectedURL = this.routerService.urlFor('parent.child', queryParams);

assert.equal('/child?filter=[user][name][$contains]=foo', expectedURL);
Copy link
Contributor

@sukima sukima Mar 14, 2024

Choose a reason for hiding this comment

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

question: This looks off. are we sure this is encoded correctly?

Per RFC3986:

If data for a URI component would conflict with a reserved character's purpose as a delimiter, then the conflicting data must be percent-encoded before the URI is formed.

And states that = is indeed a reserved character as a sub-delim. I'm a little confused how to parse this. Is filter the key to the key/value pair or is [user][name][$contains] or filter=[user][name][$contains] the key?

suggestion: per this SO answer a convention might be: ?filter[user][name][$contains]=foo instead.

});
}

['@test RouterService#urlFor returns URL for simple route with null query params'](assert) {
assert.expect(1);

Expand Down