www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1346] New: std.uri.decode/decodeComponent do not decode '+' plus

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1346

           Summary: std.uri.decode/decodeComponent do not decode '+' plus
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: alan akbkhome.com


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; }


-- 
Jul 18 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1346


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID
            Summary|std.uri.decode/decodeCompone|std.uri.decode/decodeCompone
                   |nt do not decode '+' plus   |nt do not decode '+' plus





They are not supposed to decode '+'. URI encode/decode are supposed to be
reversible operations, and changing '+' to ' ' is not reversible.


-- 
Sep 03 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1346


alan akbkhome.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |





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..


-- 
Sep 03 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1346






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.


-- 
Sep 03 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1346


alan akbkhome.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement




-- 
Sep 03 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1346


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |INVALID





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.


-- 
Sep 03 2007