Skip to content

Should URLEscape convert space characters to '+' or '%20'? #502

@hoisie

Description

@hoisie
I have a small program trying to download the following file, via http.Get:

http://www.sfmta.com/cms/uploadedfiles/dpt/bike/Safety/Chapter%202_General%
20Bicycle%20Rules.pdf

When http.Get handles the url, the combination of http.URLUnescape (in 
http.ParseURL) and http.URLEscape (in req.Write) converts the url into 
this:

http://www.sfmta.com/cms/uploadedfiles/dpt/bike/Safety/Chapter+2_General+Bi
cycle+Rules.pdf

However, that link returns a 404. 

Is there a reason why %20 is converted to '+'? Would it be safer to use 
%20? 

Relevant code is here:

package main

import "http"

func main() {
        rawurl := 
`http://www.sfmta.com/cms/uploadedfiles/dpt/bike/Safety/Chapter%202_General
%20Bicy
cle%20Rules.pdf`
        url,err := http.ParseURL (rawurl )
        if err != nil {
                println("error parsing", err)
        }
        println("Final url", url.String())

        resp,_,err := http.Get ( rawurl )
        if err != nil {
                println("error downlaoding", err.String())
        }
        println(resp.StatusCode);

}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions