Giter VIP home page Giter VIP logo

Comments (6)

juliangruber avatar juliangruber commented on June 2, 2024

can you provide an example without any library that still fails? in this example it could as well be expected browser or backbone behavior

from browser-run.

kamilogorek avatar kamilogorek commented on June 2, 2024

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.

from browser-run.

kamilogorek avatar kamilogorek commented on June 2, 2024

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

from browser-run.

juliangruber avatar juliangruber commented on June 2, 2024

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; // "#тест"

from browser-run.

wraithgar avatar wraithgar commented on June 2, 2024

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.

from browser-run.

kamilogorek avatar kamilogorek commented on June 2, 2024

Great catch @wraithgar! Thanks :)

from browser-run.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.