Different behaviours of treating \ (backslash) in the url by FireFox and Chrome

34,982

Solution 1

The unified solution to deal with backslash in a URL is to use %5C. RFC 2396 did not allow that character in URLs at all (so any behavior regarding that character was just error-recovery behavior). RFC 3986 does allow it, but is not widely implemented, not least because it's not exactly compatible with existing URL processors.

Chrome, in particular, does the same thing as IE: assumes you meant a forward slash any time you type a backslash, as you discovered, because that's what Windows file paths do.

Solution 2

Try using the Slashy add-on in the firefox to help you with it.Here's a link to it.

Slashy

Solution 3

This backslash auto conversion issue has fixed in Chrome version >= 53.0.2785.116.

Now the backslashes are treated properly as %5C.

Share:
34,982
Shoaib Nawaz
Author by

Shoaib Nawaz

I help people as I learn from their problems React/Node/WebPack/JS/jQuery BiQuery/ Data Warehousing/ Data Pipe-lining AWS Webservices Laravel Php/Python Developer Linux System Administration

Updated on February 12, 2021

Comments

  • Shoaib Nawaz
    Shoaib Nawaz over 3 years

    BACKGROUND

    According to my experience when my ubuntu workstation is configured on domain with active directory, the user name created for me was according to the following pattern.

    domain_name\user_name

    Using the userdir extensions of apache on linux will require to use user name in the URL in order to access public_html in the home directory.

    http://localhost/~domain_name\user_name

    PROBLEM A:

    Chrome converts all the backslash '\' characters in the URL to forward slash '/' and the resultant url becomes as under that is totally different and always results Not Found.

    http://localhost/~domain_name/user_name

    Firefox on the other hand does not convert back slash to forward slash so http request to intended target is served by web server.

    Common solution is to encode back slash in %5C.
    

    PROBLEM B:

    If we use a similar path (containing \ in path) in CSS @import construct, the import process of css file as HTTP Get Request is failed by reporting 404 error and the URL reported in the 404 error miss the presence of \ altogether. It means \ is removed from the URL before to invoke GET request against it.

    This behavior is common in Firefox and Chrome. But they have uncommon solutions

    Firefox needs escaped back slash to work in css import process.

    @import url("http://localhost/~domain_name\\user_name/path/to/css");

    Chrome as usual needs an encoded back slash solution.

    @import url("http://localhost/~domain_name%5Cuser_name/path/to/css");

    • What is the unified solutions to deal with \ in URL?
    • Is there a way to avoid a \ to appear in user name?
  • Boris Zbarsky
    Boris Zbarsky about 12 years
    Can you link to your testcase? I just tested it locally, and it sure seems to work fine.
  • Julian Reschke
    Julian Reschke about 12 years
    I don't think RFC 3986 changed the status of a bare "\" in a URI; it remains invalid.
  • slayedbylucifer
    slayedbylucifer over 9 years
    you just saved me... :) +1
  • Ryan
    Ryan about 7 years
    Note that there is currently a bug in Firefox where it modifies the URL bar to create a user-friendly looking URL, but which can't be copied and pasted now because it is no longer properly URL encoded: bugzilla.mozilla.org/show_bug.cgi?id=1026938
  • bit2shift
    bit2shift over 6 years
    I'm pretty sure it hasn't. It still happens in Chrome 62.0.3202.89 when typing in the address bar or when using window.location = "<url>"; in DevTools' console.
  • cowlinator
    cowlinator over 3 years
    Link results in a 404
  • cafebabe1991
    cafebabe1991 over 3 years
    Seems like the plugin was removed. Ill try to find something similar
  • cafebabe1991
    cafebabe1991 over 3 years
    @cowlinator - plugin link has been updates