tags:

views:

41

answers:

4

I have a web page that pulls in several javascript files in the HEAD section. The path to one of those files is generated dynamically, and I'm seeing an issue with some paths that include the # character. For example, the following path does not resolve correctly, and therefore the .js file does not load (even though I've verified that it exists):

<script src="\\remote_machine\share\test\this is #3 test\test.js"></script>

I'm wondering what the special meaning of '#3' is in this situation. I've tried replacing the # character with the equivalent html entity, like so:

<script src="\\remote_machine\share\test\this is &#35;3 test\test.js"></script>

but that does not resolve the issue. Further, I notice that the following path does resolve correctly (assuming the file exists):

<script src="\\remote_machine\share\test\this is # test\test.js"></script>

Could anyone explain the meaning of '#3' in the context of html as described? What's the recommended fix?

EDIT: I've tried replacing the '#' with "%23" in all three examples above. The first two remain broken, and the third no longer works. If I additionally replace all spaces with %20, I get the same result.

+1  A: 

You need to use URL encoding:

<script src="\\remote_machine\share\test\this%20is%20%23%20test\test.js"></script>

And try the file URI scheme:

<script src="file:////remote_machine/share/test/this%20is%20%23%20test/test.js"></script>
Gumbo
%35 is a 5. I think you mean %23 (0x23 == 35)
Daniel LeCheminant
When I replace my # characters with %23 in the above examples, all three are broken. Before doing that, only the first two are broken. If I additionally replace all spaces with %20, I get the same result.
Odrade
+1  A: 

Try replacing your # with %23. And while you're at it, I'd replace your spaces with %20 as well

David Hedlund
<script src="\\remote_machine\share\test\this is # test\test.js"></script> works, but <script src="\\remote_machine\share\test\this is %23 test\test.js"></script> does not. Neither does <script src="\\remote_machine\share\test\this%20is%20%23%20test\test.js"></script>
Odrade
A: 

Nothing past # is sent to the server, so you would need to use proper URL encode.

Here is a reference to URL encoded characters: http://w3schools.com/tags/ref%5Furlencode.asp

The '#' symbol would be %35.

kinections
Why is everyone saying that `#` is encoded as `%35`? Percent encoding uses hex...
Daniel LeCheminant
+1  A: 

Apart from the issue with the hash and spaces (which should indeed be encoded as %23 and %20 respectively), you've also got backslashes. Backslashes aren't directory separators in URLs. A URL is not the same as a filename, and what you've got there isn't even a filename, it's a UNC path, for local-area Windows networking.

There is no standard way to embed a UNC path in a URL; Windows networking has no place on the web and you shouldn't include references to resources on a Windows network in a web page. That js needs to be on a proper web server that you can reference with normal HTTP URLs.

If you must try:

file://remote_machine/share/test/this%20is%20%23%20test/test.js     # works on IE, Chrome, Opera
file://///remote_machine/share/test/this%20is%20%23%20test/test.js  # works on IE, Firefox

(Neither works on Safari.)

bobince