olivernn / davis.js

RESTful degradable JavaScript routing using pushState
http://davisjs.com
532 stars 58 forks source link

Sanity checking when building a Davis.Request object from JSON #10

Closed jbaudanza closed 13 years ago

jbaudanza commented 13 years ago

I've been seeing some error reports from inside of Davis.Request:

Uncaught TypeError: Cannot call method 'split' of undefined

which corresponds to this line:

this.queryString = raw.fullPath.split("?")[1];

I've only seen these errors come from Hoptoad. I haven't been able to reproduce locally from inside my app.

The only code path I can imagine this happening is when a Davis.Request object is constructed from event.state on a popstate event.

I've noticed this exact error happening in the test suite inside of the "binding and triggering the pop state event" test. Davis.Request doesn't know how to rebuild itself from "foo".

In general, I don't like writing defensive code, but I wonder if it makes sense to do some sanity checking on the data inside of event.state.

jbaudanza commented 13 years ago

I should add, these errors appear to be coming from Chrome, where the hashRouting extension should be disabled.

olivernn commented 13 years ago

In the latest release, which I'll push later today, I have made sure that there are defaults when creating a Davis.Request, this should stop these errors showing up. I've also been a bit more careful about the data that we pull out of the state object, making sure it is something that Davis put in the state object before using that data to build a request. Hopefully this will mean this error goes away now.

olivernn commented 13 years ago

Should be solved in the latest release