Patch to be tolerant of whitespace in URLs

Philip Boulain prb at
Sun May 25 12:29:54 BST 2008

On Sat, 2008-05-24 at 14:02 +0200, John Tytgat wrote: 
> You go through a great pain to use snprintf(). Why not something like:
> + 			(*result)[  i] = '%'
> + 			(*result)[++i] = digit2lowcase_hex(space >> 4);
> + 			(*result)[++i] = digit2lowcase_hex(space & 0xF);

'Cause I wanted to use standard hex-conversion functions. Added John's
implementation to utils/utils.h, as it's not URL-specific, though, and
the null-avoidance was pretty unpleasant, yeah.

> Algorithmically it would be better to start from the end of *result buffer
> as that would avoid calling memmove() but that perhaps stretching things a
> bit. ;-)

Don't believe that that's actually correct? Either way you need to
insert characters, and that means shifting stuff out the way. I suppose,
given that the string has been previously scanned for space, one could
be clever enough to move the string the right distance the first time,
but for the average URL length and internal whitespace density I doubt
it's worth the hit to code simplicity. ;)

> It might also enhance the code quality if we would use a temporary variable
> holding *result and use that. that the malloc is earlier, yes, I think that's probably clearer, as there's only one exit point before I can make temporary==*result. Reduces the parenthetical cancer.

> > -	for (i = 0; (unsigned)i != len; i++) {
> > +	for (i = 0; (size_t)i + 2 < len; i++) {
> Wouldn't it be better to use size_t for i from the start ?

Well, it was int when I got 'ere, gov'ner. But, looking at it, i never
needs to be negative, just zero, so seems safe to change.

Revised version of patch attached.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: netsurf-url-whitespace4.patch
Type: text/x-patch
Size: 6229 bytes
Desc: not available
Url :

More information about the netsurf-dev mailing list