Bug 1346 – std.uri.decode/decodeComponent do not decode '+' plus
Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2007-07-18T10:35:00Z
Last change time
2015-06-09T05:14:41Z
Assigned to
bugzilla
Creator
alan
Comments
Comment #0 by alan — 2007-07-18T10:35:24Z
std.stdio.writefln("%s", std.uri.decode("cat+dog"));
expected output:
"cat dog"
actual output "cat+dog"
(you would normally get this by posting a web page with a space (eg. search for something with a space on google)
Suggested Fix:
Line 269 of std/uri.d
if (C == '+') { R[Rlen] = ' '; Rlen++; continue; }
Comment #1 by bugzilla — 2007-09-03T15:02:22Z
They are not supposed to decode '+'. URI encode/decode are supposed to be reversible operations, and changing '+' to ' ' is not reversible.
Comment #2 by alan — 2007-09-03T18:59:40Z
http://hk.php.net/manual/en/function.urlencode.php
"Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type. This differs from the ยป RFC 1738 encoding (see rawurlencode()) in that for historical reasons, spaces are encoded as plus (+) signs."
It looks like it was necessary to produce 2 versions in PHP, as real-world usage demanded the ability to encode and decode real-urls, as per the x-www-frm-urlencoded media type.
I've bumped it to a enhancement - although it's pretty critical if you use D to respond to CGI requests..
Comment #3 by alan — 2007-09-03T19:01:44Z
enhancement being that either another method is required, or an additional flag to decode/encode...
I'd leave the bug as open "fix needed" - as the original fix is more a workaround now.
Comment #4 by bugzilla — 2007-09-03T20:51:11Z
The encode/decode functions correspond to the equivalent functions in the ECMA 262 spec (i.e. javascript). I'm very reluctant to deviate from it, considering how pervasive javascript is.