Issue #345 - discard leading spaces in href

This commit is contained in:
Geoff McLane 2016-02-01 20:07:55 +01:00
parent e8ca2aa5f3
commit 7d0d8a853a

View file

@ -1500,15 +1500,31 @@ void TY_(CheckUrl)( TidyDocImpl* doc, Node *node, AttVal *attval)
if ( cfgBool(doc, TidyFixUri) && escape_count )
{
Bool hadnonspace = no;
len = TY_(tmbstrlen)(p) + escape_count * 2 + 1;
dest = (tmbstr) TidyDocAlloc(doc, len);
for (i = 0; 0 != (c = p[i]); ++i)
{
if ((c > 0x7e) || (c <= 0x20) || (strchr("<>", c)))
pos += sprintf( dest + pos, "%%%02X", (byte)c );
{
if (c == 0x20)
{
/* #345 - special case for leading spaces - discard */
if (hadnonspace)
pos += sprintf( dest + pos, "%%%02X", (byte)c );
}
else
{
pos += sprintf( dest + pos, "%%%02X", (byte)c );
hadnonspace = yes;
}
}
else
{
hadnonspace = yes;
dest[pos++] = c;
}
}
dest[pos] = 0;