getoutreach / epf

A framework for keeping your Ember.js apps in sync.
http://epf.io
MIT License
369 stars 33 forks source link

url-encoded IDs #71

Closed heartsentwined closed 10 years ago

heartsentwined commented 11 years ago

This is either a bug, or just a gotcha report for future googlers.

class App.SearchRoute extends Em.Route
  model: (params) ->
    @session.load 'search', params.search_term

Whenever params.search_term include a url-encoded string, the above will throw several of this:

Error while loading route: TypeError {} 
Uncaught TypeError: Cannot call method 'toString' of undefined 

The url-encoded string is the default in ember, however. Let's say your entry URL is /search/便 (just a random non-safe character), the params object will give you Object {search_term: "%E4%BE%BF"}.

The fix / workaround:

class App.SearchRoute extends Em.Route
  model: (params) ->
    @session.load 'search', decodeURIComponent params.search_term

(A further step can be taken to translate + into `, whichdecodeURIComponent` doesn't do.)

Sidenote: the server - rails in my case - happily accepts the request in both cases, and processes them correctly.

ghempton commented 11 years ago

Thanks for pointing out this gotcha. This feels like something related to Ember.js proper?

heartsentwined commented 11 years ago

I'm not sure which is the expected responsibility: should the params object perform decoding or faithfully represent the raw URL? or should the ID stringifier / normalizer catch this and decode it as part of normalization?

heartsentwined commented 11 years ago

I'll report this at ember too.

ghempton commented 10 years ago

I believe this to be an Ember.js issue, am going to close and we can track there.