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

Gin master build failed #1511

Closed
chainhelen opened this issue Aug 24, 2018 · 2 comments
Closed

Gin master build failed #1511

chainhelen opened this issue Aug 24, 2018 · 2 comments

Comments

@chainhelen
Copy link
Contributor

chainhelen commented Aug 24, 2018

@thinkerou @appleboy
Gin master, the commit is 0da5b0c85ac2539e775a7e63aebf3e0b5808dab4

Description

refercens
#1510 test(not review): add go1.11
#1383 Support map as query string or post form parameters
#1362 How can I get map[string]string filed on PostForm?
#1106 Map as query parameter

Build failed in go master but ok in other go version.
image

Reason

This because this commit in go master, add this func validQuery

// validQuery reports whether s is a valid query string per RFC 3986
// Section 3.4:
//     query       = *( pchar / "/" / "?" )
//     pchar       = unreserved / pct-encoded / sub-delims / ":" / "@"
//     unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
//     sub-delims  = "!" / "$" / "&" / "'" / "(" / ")"
//                   / "*" / "+" / "," / ";" / "="
func validQuery(s string) bool {
   pctEnc := 0
	for _, r := range s {
   	if pctEnc > 0 {
   		if uint32(r) > 255 || !ishex(byte(r)) {
   			return false
   		}
   		pctEnc--
   		continue
   	} else if r == '%' {
   		pctEnc = 2
   		continue
   	}
		if 'A' <= r && r <= 'Z' {
   		continue
   	}
   	if 'a' <= r && r <= 'z' {
   		continue
   	}
   	if '0' <= r && r <= '9' {
   		continue
   	}
   	switch r {
   	case '-', '.', '_', '~', '!', '$', '&', '\'', '(', ')',
   		'*', '+', ',', ';', '=', ':', '@', '/', '?':
   		continue
   	default:
   		return false
   	}
   }
	return true
}

Then I copy these into local workspace, test like below

func main() {
    fmt.Printf("%t\n", validQuery("both=GET&id=main&id=omit&array[]=first&array[]=second&ids[a]=hi&ids[b]=3.14"))
    fmt.Printf("%t\n", validQuery("foo=bar&page=10&id=2"))
}

// build and run, get 
false
true

Summarize

In go master, if url include '[' or ']', will be QueryEscape according to RFC 3986. So don't parse url.query

@chainhelen
Copy link
Contributor Author

Maybe we can parse this type query in gin itself.

@thinkerou
Copy link
Member

@chainhelen fix issue, please see #1510 and help review, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants