[thelist] http GET and difficult strings

Kasimir K evolt at kasimir-k.fi
Sun Apr 18 02:06:09 CDT 2004


Hello people,

I must pass strings to an iframe using GET, along these lines
		
iframe = document.createElement('iframe');
iframe.src = iframe_url + querystring; 
document.getElementById('append_iframe_here').appendChild(iframe);

where 'querystring' looks something like this:
?string1=lorem%20ipsum&string2=dolor%20sit%20amet

Looks easy enough... but my problems started, when I wanted to have '+' 
in my string. The iframe got it as a space, not as a plus sign. Ok, I 
did encodeURIComponent to the srtings, and '+' worked ok. But it got 
trickier, as some of the strings will be used in PHP code as conditions, 
so I need to pass strings like '!foo && bar', and even worse, Spanish 
sentences: '¿Cuantos años tienes?'...

As the strings may be already encoded, I need to decode them first. But 
¡Alas!, when I give a 'ñ' to decodeURIComponent, it informs me: 
"malformed URI sequence"... well, fair enough, 'ñ' is not valid in URLs. 
So I decied to use unescape instead, as it is not so picky. But unescape 
  plays only with ISO-Latin-1...

Knowing then what I know now,I would have designed my application so, 
that the iframe would have asked for the strings on the client side with 
JS, but it's too late to change this, and I have to pass the strings to 
the server side.

Ok, then my question:

What would be the berst way to pass "string1=!foo && bar" and 
"string2=¿Cuantos años tienes?" in a querystring?


please,
.k


More information about the thelist mailing list