Re: How to handle spaces/blanks in URLs
"Wolfgang Fahl - BITPlan" <[email protected]>
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Organization | bitplan GmbH |
| Message-ID | <[email protected]> |
Russell wrote:
> Safari tries the http://www.bit%20plan.com approach as well. I think
> that is correct.
I tried to change the behaviour but failed to get a consistent result
because
testLinkUrlAcrossLineBreaks()
would then fail.
So I had to comment out the line that does the encoding again.
Otherwise the change is prepared
/**
*
Trims
whitespace
from
the
ends,
and
encodes
from
the
middle.
*
Spaces
within
quotes
are
respected.
*/
static
String encodeSpaces( String s ) {
s = s.trim();
// if no spaces we are fine
if
(s.indexOf(
' '
) < 0)
return
s;
boolean
inQuotes =
false
;
StringBuffer sb =
new
StringBuffer();
char
[] chars = s.toCharArray();
// loop over oper the chars of the URL
for
(
int
i = 0; i < chars.length; i++) {
// get the current character
char
aChar = chars[i];
// toggle quotation and add quote
if
(aChar ==
'"'
|| aChar ==
'\''
) {
inQuotes = !inQuotes;
sb.append( aChar );
// append everything in quotes and printable chars above space
}
else
if
(inQuotes) {
sb.append( aChar );
}
else
if
(aChar >
' '
) {
sb.append( aChar );
}
else
if
(aChar==
' '
) {
// encode spaces
//
TODO
check what to do about breaking testLinkUrlAcrossLineBreaks then
...
// sb.append("%20");
}
}
return
sb.toString();
}
BITPlan - smart solutions
Pater-Delp-Str. 1, D-47877 Willich Schiefbahn
Tel. +49 1805 - BITPLAN / +49 1805 248 752, Fax +49 2154 811-481
Web: http://www.bitplan.de
bitplan GmbH, Willich - HRB 6820 Krefeld, VAT-ID: 10258040548, Geschäftsführer: Wolfgang Fahl
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Httpunit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/httpunit-develop