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

[BUGFIX release] Fix array QP serialization #14171

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/ember-routing/lib/system/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ let Route = EmberObject.extend(ActionHandler, Evented, {
// urlKey isn't used here, but anyone overriding
// can use it to provide serialization specific
// to a certain query param.
if (defaultValueType === 'array') {
if (defaultValueType === 'array' && Array.isArray(value)) {
return JSON.stringify(value);
}
return `${value}`;
Expand Down
19 changes: 19 additions & 0 deletions packages/ember/tests/routing/query_params_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2530,6 +2530,25 @@ if (isEnabled('ember-routing-route-configured-query-params')) {
equal(router.get('location.path'), '/?foo=3', 'url is correct');
});

QUnit.test('previously set array queryParam is preserved when a controller property is set and the route is refreshed.', function() {
App.ApplicationController = Controller.extend({
queryParams: ['array', 'foo'],
array: [],
foo: null,
});

startingURL = '/';
bootApplication();
let applicationRoute = container.lookup('route:application');
let applicationController = container.lookup('controller:application');
run(applicationController, 'set', 'array', [1]);
run(() => {
applicationController.set('foo', 'bar');
applicationRoute.refresh();
});
equal(decodeURIComponent(router.get('location.path')), `/?array=[1]&foo=bar`, 'url is correct');
});

QUnit.test('Use Ember.get to retrieve query params \'refreshModel\' configuration', function() {
expect(6);
App.ApplicationController = Controller.extend({
Expand Down