Skip to content

Commit

Permalink
Fixed issue #65: urlEncode doesn't properly handle < 0x10.
Browse files Browse the repository at this point in the history
Added reserve() calls in urlEncode/urlDecode that should improve memory management in certain situations (e.g. for ascii field names and numeric values in query strings).
  • Loading branch information
s-ludwig committed Jul 1, 2012
1 parent c8a03f9 commit 3c881c5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions source/vibe/textfilter/urlencode.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ import std.format;
string urlEncode(string str)
{
auto dst = appender!string();
dst.reserve(str.length);
filterUrlEncode(dst, str);
return dst.data;
}

string urlDecode(string str)
{
auto dst = appender!string();
dst.reserve(str.length);
filterUrlDecode(dst, str);
return dst.data;
}
Expand All @@ -37,11 +39,11 @@ void filterUrlEncode(R)(ref R dst, string str)
case 'A': .. case 'Z'+1:
case 'a': .. case 'z'+1:
case '0': .. case '9'+1:
case '-': case '_': case '.': case '~':
case '-': case '_': case '.': case '~':
dst.put(str[0]);
break;
default:
formattedWrite(dst, "%%%x", str[0]);
formattedWrite(dst, "%%%02x", str[0]);
}
str = str[1 .. $];
}
Expand Down

0 comments on commit 3c881c5

Please sign in to comment.