Asked  7 Months ago    Answers:  5   Viewed   22 times

Is a URI (specifically an HTTP URL) allowed to contain one or more space characters? If a URL must be encoded, is + just a commonly followed convention, or a legitimate alternative?

In particular, can someone point to an RFC that indicates that a URL with a space must be encoded?

Motivation for question: While beta-testing a web site, I noted that some URLs were constructed with spaces in them. Firefox seemed to do the right thing, which surprised me! But I wanted to be able to point the developers to an RFC so that they would feel the need to fix those URLs.

 Answers

39

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.

Tuesday, June 1, 2021
 
Elxx
answered 7 Months ago
38

You'll need an .htaccess file (but you won't need to change it each time you add a page):

RewriteEngine On 
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]

Now in your index.php you can access the requested url in $_GET['url'], map it to the correct file and then include it.

Note: Put the RewriteBase comment in there in case you need to uncomment it as some configurations require this.

Wednesday, March 31, 2021
 
Tak
answered 9 Months ago
Tak
52

Because static class members are not stored in the class instance, that's why a static would work.

Storing an object inside another object of the same type would break the runtime - infinite size, right?

What would sizeof return? The size of the object needs to be known by the compiler, but since it contains an object of the same type, it doesn't make sense.

Friday, June 25, 2021
 
Jubair
answered 6 Months ago
75

No, you can't do what yo try to do. And you probably shouldn't try. The fact that you want some data inside a variable called DATA means that your POST payload (or your GET query string) will look like

DATA=somevar%3Dsomeval%26somevar2%3Dsomeotherval

If it was (as you want it to be) like

DATA=somevar=someval&somevar2=someotherval

it would mean:

DATA has a value of 'somevar=someval'

somevar2 has a value of 'someotherval'

This is because each variable has the form VARIABLE_NAME=VALUE, and they are separated by '&'.

Check this yourself in your favourite browser debugger (I use firebug and chrome built-in dev tools). So, the question is: why are you trying to do this? Knowing that it would be easier to help you achieve your goals.

EDIT: the example was wrong

Tuesday, August 24, 2021
 
sathiya
answered 4 Months ago
46

The UrlEncodedFormEntity is basically a StringEntity with a custom constructor, you don't actually have to use it in order to create a usuable entity.

String entityValue = URLEncodedUtils.format(parameters, HTTP.UTF_8);
// Do your replacement here in entityValue
StringEntity entity = new StringEntity(entityValue, HTTP.UTF_8);
entity.setContentType(URLEncodedUtils.CONTENT_TYPE);
// And now do your posting of this entity
Thursday, September 23, 2021
 
hnkk
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share