Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/url: problem with queryescape? #11249

Closed
vsdutka opened this issue Jun 17, 2015 · 9 comments
Closed

net/url: problem with queryescape? #11249

vsdutka opened this issue Jun 17, 2015 · 9 comments

Comments

@vsdutka
Copy link

vsdutka commented Jun 17, 2015

If recieve error when use url.QueryUnescape with query string like "Z_FILTER=%25\u0414\u0430\u0432\u044B\u0434\u043E\u0432%25\u0418\u0432\u0430\u043D%25"
But it is normal query string

@vsdutka
Copy link
Author

vsdutka commented Jun 17, 2015

Sorry/ Queryr string is "Z_FILTER=%25%u0414%u0430%u0432%u044B%u0434%u043E%u0432%25%u0418%u0432%u0430%u043D%25"

@bradfitz
Copy link
Contributor

What's the problem?

@adg adg changed the title url.QueryUnescape and query string like "Z_FILTER=%25Давыдов%25Иван%25" net/url: problem with queryescape? Jun 18, 2015
@vsdutka
Copy link
Author

vsdutka commented Jun 18, 2015

Test case

func main(){

s, err := url.QueryUnescape("%25%u0414%u0430%u0432%u044B%u0434%u043E%u0432%25%u0418%u0432%u0430%u043D%25")

if err != nil {

    fmt.Println("Error - ", err)

}

fmt.Println(s)

}

Error - invalid URL escape "%u0"

2015-06-17 15:56 GMT+03:00 Brad Fitzpatrick notifications@github.com:

What's the problem?


Reply to this email directly or view it on GitHub
#11249 (comment).

@adg
Copy link
Contributor

adg commented Jun 18, 2015

%u shouldn't appear in any valid urlencoded string: https://en.wikipedia.org/wiki/Percent-encoding#Non-standard_implementations

@vsdutka
Copy link
Author

vsdutka commented Jun 18, 2015

But this implementation massively used by IE.

2015-06-18 9:19 GMT+03:00 Andrew Gerrand notifications@github.com:

%u shouldn't appear in any valid urlencoded string:
https://en.wikipedia.org/wiki/Percent-encoding#Non-standard_implementations


Reply to this email directly or view it on GitHub.

@adg
Copy link
Contributor

adg commented Jun 18, 2015

Can you show me where/how? I can't find information about this.

@vsdutka
Copy link
Author

vsdutka commented Jun 18, 2015

Our application have a lot of pages with code like:

function L_POONAME_W_EKB_FLAG_LOV() {
var filter = prompt("Введите критерий поиска для Лицо - Владелец А/М",
"%");
if (filter == null) { return; }
if (filter == "") { return; }
var the_pathname = location.pathname;
var i = the_pathname.indexOf ('/:');
var j = the_pathname.indexOf ('/', ++i);
if (i != -1)
{
// Syntactically incorrect url so it needs to be corrected
the_pathname = the_pathname.substring (j, the_pathname.length);
}; // (i != -1)
frmLOV = open("axiidvehtr$iidvehtr.l_pooname_w_ekb_flag_listofval" +
"?Z_FILTER=" + *escape(filter) *+ "&Z_MODE=Q" +
"&Z_CALLER_URL=" + *escape(location.protocol + '//' +
location.host + the_pathname + location.search) *+
"&Z_ISSUE_WAIT=Y",
"winLOV",
"scrollbars=yes,resizable=yes,width=400,height=400");
if (frmLOV.opener == null) {
frmLOV.opener = self;
}
}

For unicode chars *escape *produce string like "%uXXXX"

2015-06-18 10:27 GMT+03:00 Andrew Gerrand notifications@github.com:

Can you show me where/how? I can't find information about this.


Reply to this email directly or view it on GitHub
#11249 (comment).

@vsdutka
Copy link
Author

vsdutka commented Jun 18, 2015

I use code like

...

r.URL.RawQuery = decodeUnicodeEscapedChars(r.URL.RawQuery)

...

func decodeUnicodeEscapedChars(s string) string {

re := regexp.MustCompile(`%u[0-9ABCDEF]{4}`)

return re.ReplaceAllStringFunc(s, func(s string) string {

    t, err := strconv.Unquote("\"" + `\u` + s[2:] + "\"")

    if err != nil {

        panic(err)

    }

    return t

})

}

But i think its not so good practice.

2015-06-18 13:28 GMT+03:00 Vyacheslav Dutka vsdutka@gmail.com:

Our application have a lot of pages with code like:

function L_POONAME_W_EKB_FLAG_LOV() {
var filter = prompt("Введите критерий поиска для Лицо - Владелец А/М",
"%");
if (filter == null) { return; }
if (filter == "") { return; }
var the_pathname = location.pathname;
var i = the_pathname.indexOf ('/:');
var j = the_pathname.indexOf ('/', ++i);
if (i != -1)
{
// Syntactically incorrect url so it needs to be corrected
the_pathname = the_pathname.substring (j, the_pathname.length);
}; // (i != -1)
frmLOV = open("axiidvehtr$iidvehtr.l_pooname_w_ekb_flag_listofval" +
"?Z_FILTER=" + *escape(filter) *+ "&Z_MODE=Q" +
"&Z_CALLER_URL=" + *escape(location.protocol + '//' +
location.host + the_pathname + location.search) *+
"&Z_ISSUE_WAIT=Y",
"winLOV",
"scrollbars=yes,resizable=yes,width=400,height=400");
if (frmLOV.opener == null) {
frmLOV.opener = self;
}
}

For unicode chars *escape *produce string like "%uXXXX"

2015-06-18 10:27 GMT+03:00 Andrew Gerrand notifications@github.com:

Can you show me where/how? I can't find information about this.


Reply to this email directly or view it on GitHub
#11249 (comment).

@bradfitz
Copy link
Contributor

I don't think we should encourage it by enshrining it in the standard library. Anybody can write a package to do this and place it elsewhere on Github.

But such a function probably should be more careful with allocations than decodeUnicodeEscapedChars above is.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants