Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?
like image 738
Shoaib Nawaz Avatar asked May 03 '12 19:05

Shoaib Nawaz


People also ask

What does a backslash mean in a URL?

Historically, it's common for URLs with a trailing slash to indicate a directory, and those without a trailing slash to denote a file: http://example.com/foo/ (with trailing slash, conventionally a directory) http://example.com/foo (without trailing slash, conventionally a file) But they certainly don't have to.

Are backslash allowed in URL?

If you try to enter a backslash in a Web address you will likely get an error. They are rarely used in URLs. Thus they shouldn't be used when discussing Web addresses. Backslashes are often used in programming languages and old DOS directories, so on occasion developers and nerds might correctly use the name.

How do you add a backslash to a URL?

Experiments of Mixing Slashes And found that all those browsers accept URLs written with forward slashes ( / , the correct form), URLs written with backslashes ( \ , an incorrect form) and URLs written with mixed slashes in their path part ( / & \ , another incorrect form).

What is the function of backslash?

The backslash ( \ ) is a typographic and/or keyboard mark that is used in some programming languages and other computing contexts. In Windows systems, for example, the backslash is used to separate elements of a file path, for example: C:\Documents\User\File.


2 Answers

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.

like image 164
Boris Zbarsky Avatar answered Sep 20 '22 05:09

Boris Zbarsky


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

Slashy

like image 26
cafebabe1991 Avatar answered Sep 20 '22 05:09

cafebabe1991