Skip to content

normalize method decodes single quote in query string #320

@shrkw

Description

@shrkw

version: 2.5.2

When call normalize, single quote (%27) in query string will decode to '. Is this expected behavior?

4.2.8@2.3.3 (main)> uri = Addressable::URI.parse("https://お名前.com/ほげ/ふが.jpg")
=> #<Addressable::URI:0x5c1cb04 URI:https://お名前.com/ほげ/ふが.jpg>
4.2.8@2.3.3 (main)> uri.normalize
=> #<Addressable::URI:0x5b475e4 URI:https://xn--t8jx73hngb.com/%E3%81%BB%E3%81%92/%E3%81%B5%E3%81%8C.jpg>
4.2.8@2.3.3 (main)> uri.to_s
=> "https://お名前.com/ほげ/ふが.jpg"
4.2.8@2.3.3 (main)> que = {}
=> {}
4.2.8@2.3.3 (main)> que[:'response-content-disposition'] = "attachment;filename*=UTF-8''ふが.jpg"
=> "attachment;f;filename*=UTF-8''\xE3\x81\xB5\xE3\x81\x8C.jpg"
4.2.8@2.3.3 (main)> uri.query_values = que
=> {
    :"response-content-disposition" => "attachment;filename*=UTF-8''\xE3\x81\xB5\xE3\x81\x8C.jpg"
}
4.2.8@2.3.3 (main)> uri.to_s
=> "https://お名前.com/ほげ/ふが.jpg?response-content-disposition=attachment%3Bfilename%2A%3DUTF-8%27%27%E3%81%B5%E3%81%8C.jpg"
4.2.8@2.3.3 (main)> uri.normalize
=> #<Addressable::URI:0x80aeb5c URI:https://xn--t8jx73hngb.com/%E3%81%BB%E3%81%92/%E3%81%B5%E3%81%8C.jpg?response-content-disposition=attachment%3Bfilename*=UTF-8''%E3%81%B5%E3%81%8C.jpg>

As workaround, I manually concatenate each parts. Is there any better way?

4.2.8@2.3.3 (main)> uri.scheme + "://" + uri.normalized_host + uri.normalized_path + "?" + uri.query
=> "https://xn--t8jx73hngb.com/%E3%81%BB%E3%81%92/%E3%81%B5%E3%81%8C.jpg?response-content-disposition=attachment%3Bf%3Bfilename%2A%3DUTF-8%27%27%E3%81%B5%E3%81%8C.jpg"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions