Href Syntax: Is It Okay to Have Space in File Name

href syntax : is it okay to have space in file name

The src attribute should contain a valid URL. Since space characters are not allowed in URLs, you have to encode them.

You can write:

<img src="buttons/bu%20hover.png" />

But not:

<img src="buttons/bu+hover.png" />

Because, as DavidRR rightfully points out in his comment, encoding space characters as + is only valid in the query string portion of an URL, not in the path itself.

Link to filenames with spaces in Bitbucket Markdown

There was, in fact, a bug on Bitbucket's side, however, the bug is now fixed.

Assuming your file is called File with spaces.md and the text you want to be displayed is Link, either of these two methods will work:

* [Link](File with spaces.md)
* [Link](File%20with%20spaces.md)

JS - How to deal with space in file names?

You can use encodeURI(content.uri) to ensure that the string is correctly encoded as a URI and will match what you see in window.src (the HTML is URI-encoded automatically to make it a valid URL). Ideally, stick to legal URIs and avoid the issue.

<html><img id="window-1" src="http://url.net/demo 1.png"><img id="window-2" src="http://url.net/demo 2.png">
<script> const content = { uid: 'image-1', uri: 'http://url.net/demo 1.png' }; const mediaWindows = [document.getElementById('window-1'), document.getElementById('window-2')];
function getPlayedWindow(playedContent) { return mediaWindows.find((window) => window.src === playedContent) }
console.log(getPlayedWindow(encodeURI(content.uri)));
</script>

Is a URL allowed to contain a space?

As per RFC 1738:

Unsafe:

Characters can be unsafe for a number of reasons. The space
character is unsafe because significant spaces may disappear and
insignificant spaces may be introduced when URLs are transcribed or
typeset or subjected to the treatment of word-processing programs.

The characters "<" and ">" are unsafe because they are used as the
delimiters around URLs in free text; the quote mark (""") is used to
delimit URLs in some systems. The character "#" is unsafe and should
always be encoded because it is used in World Wide Web and in other
systems to delimit a URL from a fragment/anchor identifier that might
follow it. The character "%" is unsafe because it is used for
encodings of other characters. Other characters are unsafe because
gateways and other transport agents are known to sometimes modify
such characters. These characters are "{", "}", "|", "\", "^", "~",
"[", "]", and "`".

All unsafe characters must always be encoded within a URL. For
example, the character "#" must be encoded within URLs even in
systems that do not normally deal with fragment or anchor
identifiers, so that if the URL is copied into another system that
does use them, it will not be necessary to change the URL encoding.

Spaces in URLs?

A URL must not contain a literal space. It must either be encoded using the percent-encoding or a different encoding that uses URL-safe characters (like application/x-www-form-urlencoded that uses + instead of %20 for spaces).

But whether the statement is right or wrong depends on the interpretation: Syntactically, a URI must not contain a literal space and it must be encoded; semantically, a %20 is not a space (obviously) but it represents a space.



Related Topics



Leave a reply



Submit