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

Globbed dynamic route segments aren't URL-decoded in model() hook params #15059

Closed
gabrielgrant opened this issue Mar 23, 2017 · 6 comments
Closed

Comments

@gabrielgrant
Copy link

Using current (as of 2017-03-23) versions of ember/ember-cli:

$ ember version
ember-cli: 2.12.0
node: 6.3.0
os: linux x64
$ cat package.json | grep ember-source
    "ember-source": "~2.12.0",

It seems this (or similar) issues were first addressed in #3263 which was closed in favor of a PR in #3545
#3545 is closed because of the existence of this patch from 2014, but AFAICS this it is created to urlencoding of address query params

Full example:

Given this app/router.js

Router.map(function() {
  this.route('files', function() {
    this.route('file', { path: '*path' });
  });
});

and this app/routes/files/file.js:

import Ember from 'ember';

export default Ember.Route.extend({
  model(params) {
    let fileQuery = {
      path: decodeURI(params.path)
    };
    console.log('file route', params, fileQuery);
    return this.get('store').queryRecord('file', fileQuery);
  }
});

Visiting http://localhost:4200/tmp/my%20file%20with%20spaces outputs {"path":"/tmp/my%20file%20with%20spaces"}, {"path":"/tmp/my file with spaces"}

@gabrielgrant
Copy link
Author

It looks like this was also re-addressed in #4794 which was closed after the problem was (apparently?) fixed in 2.7. It seems that may have been a reference to tildeio/route-recognizer#91 which does seem like it should address this issue (specifically "Bugfix: inconsistent decoding of dynamic segments", though I may be misinterpreting)

So not sure if maybe this should be filed over on that repo instead?

@pixelhandler
Copy link
Contributor

@gabrielgrant would you be willing to make an example in an ember-twiddle ? see https://ember-twiddle.com

@gabrielgrant
Copy link
Author

gabrielgrant commented Mar 24, 2017

It's a little strange, because, unlike a browser, the ember twiddle URL field accepts literal space characters, so you need to manually escape the spaces: /files/my%20file%20with%20spaces.json (and this results in the actual ember twiddle URI being double escaped): https://ember-twiddle.com/c313e36f1b8fb8f34afb52047b6cca9d?openFiles=templates.files.file.hbs%2C&route=%2Ffiles%2Fmy%2520file%2520with%2520spaces.json

Edit: strangely, although that link has a route query param, it seems to not actually open that route when the ember twiddle loads. Seems like a twiddle bug? Pasting /files/my%20file%20with%20spaces.json into the ember twiddle path field shows the problem

@gabrielgrant
Copy link
Author

gabrielgrant commented Mar 24, 2017

Ah, interesting. This only seems to happen when using the globbing pattern. Updated the twiddle so you can see it properly decoding non-globbed-matches now too

@gabrielgrant gabrielgrant changed the title Dynamic route segments aren't URL-decoded in model() hook params Globbed dynamic route segments aren't URL-decoded in model() hook params Mar 24, 2017
@pixelhandler
Copy link
Contributor

@gabrielgrant is this still an issue, perhaps we should close or create a new reproduction of this, what do you think?

@pixelhandler
Copy link
Contributor

Seems fine in Ember v3.5, https://ember-twiddle.com/533c63cafba79951417e490f91957c2a?openFiles=twiddle.json%2C closing this out for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants