Closed kamilogorek closed 10 years ago
can you provide an example without any library that still fails? in this example it could as well be expected browser or backbone behavior
I verified this issue using only node url parser and it seems that this is expected behavior. I guess I'll have to dig deeper into this now. Still not sure why there's a parse error though.
Well, that're surprising results.
Test case:
var tape = require('tape');
var url = require('url');
tape('unicode routes', function (t) {
var exampleUrl = 'http://example.com/тест#тест';
var link = document.createElement('a');
link.href = exampleUrl;
console.log('Simple string: тест\n');
console.log('Browser parsed pathname: ' + link.pathname.substr(1));
console.log('Node parsed pathname: ' + url.parse(exampleUrl).pathname.substr(1) + '\n');
console.log('Browser parsed hash: ' + link.hash.substr(1));
console.log('Node parsed hash: ' + url.parse(exampleUrl).hash.substr(1));
});
Results:
Simple string: теÑÑ‚
Browser parsed pathname: теÑÑ‚
Node parsed pathname: теÑÑ‚
Browser parsed hash: %D1%82%D0%B5%D1%81%D1%82
Node parsed hash: теÑÑ‚
At least we're down to hash parsing only ;)
Or not.
Here're results straight from the browser console (works same if we simply embed link into the DOM):
Test case:
var foo = document.createElement('a');
foo.href = 'http://example.com/тест#тест';
console.log('Pathname: ' + foo.pathname);
console.log('Hash: ' + foo.hash);
Results:
Pathname: /%D1%82%D0%B5%D1%81%D1%82
Hash: #тест
Completely other way around :s
this is the same if you just run that code in your browser's dev console:
var str = 'тест';
str.substr(1); // "ест"
var link = document.createElement('a');
link.href = 'http://example.com/тест#тест';
link.pathname; // "/%D1%82%D0%B5%D1%81%D1%82"
link.hash; // "#тест"
This made the example work, I think this issue can be closed
test("routes with unicode", function (t) {
location.replace('http://example.com#search/' + encodeURIComponent('тест'));
Backbone.history.checkUrl();
t.equal(router.query, "тест");
});
The syntax error was due to ä needing to be in quotes if used as an object index.
Great catch @wraithgar! Thanks :)
Some of the unicode characters are creating falsy-negatives when running using
tape-run
, but they're working correctly withbrowser-run
. 2 different cases.Using
ä
–charcode: 228
– causesSyntaxError: Parse error
and hangs process.Using cyrillic eg.
тест
– encodes incorrectly givingтеÑÑ‚
as a result instead ofтест
which causes given test fail.Simple tape test using Backbone:
results:
if you write simple test:
it will of course pass