space in url; did browser got smarter or server?

2020-04-16 03:36发布

问题:

It looks like today you no longer to have to encode spaces by %20 in your html links or image links. For example, suppose you have this image at 〔http://example.com/i/my house.jpg〕. Notice the space there. In your html code, you can just do this:

<img src="http://example.com/i/my house.jpg" alt="my house">

It work in all current version of browsers. Though, what i'm not sure is that whether the browser encodes it before requesting the url, or a particular server will do the right with with paths with space? (apache)

Addendum: sorry about the confusion. My real question is about HTTP protocol. I'll leave this one as is and mark Answered. I posted a new question here. does HTTP protocol require space be encoded in file path?

回答1:

The browser makes the correction.

You still have to encode the spaces though. Just because it works in the browsers you use doesn't make it valid, and doesn't mean it will work everywhere.

You can see a list of reserved characters and other characters that should be encoded here: http://www.blooberry.com/indexdot/html/topics/urlencoding.htm

RFC1738 specifically states:

Thus, only alphanumerics, the special characters "$-_.+!*'(),", and reserved characters used for their reserved purposes may be used unencoded within a URL.

RFC2396 takes place over RFC1738 and expounds on space usage in URLs:

The space character is excluded because significant spaces may disappear and insignificant spaces may be introduced when URI are transcribed or typeset or subjected to the treatment of word- processing programs. Whitespace is also used to delimit URI in many contexts.