Fix query parsing when blank values are present

This commit is contained in:
Justin Li 2015-06-18 10:34:52 -04:00
parent 242ba22f8c
commit 203e4e6020

View file

@ -36,16 +36,15 @@ func New(query string) (*Query, error) {
for i, length := 0, len(query); i < length; i++ { for i, length := 0, len(query); i < length; i++ {
separator := query[i] == '&' || query[i] == ';' || query[i] == '?' separator := query[i] == '&' || query[i] == ';' || query[i] == '?'
if separator || i == length-1 { last := i == length-1
if onKey {
if separator || last {
if onKey && !last {
keyStart = i + 1 keyStart = i + 1
continue continue
} }
if i == length-1 && !separator { if last && !separator && !onKey {
if query[i] == '=' {
continue
}
valEnd = i valEnd = i
} }
@ -54,10 +53,14 @@ func New(query string) (*Query, error) {
return nil, err return nil, err
} }
valStr, err := url.QueryUnescape(query[valStart : valEnd+1]) var valStr string
if valEnd > 0 {
valStr, err = url.QueryUnescape(query[valStart : valEnd+1])
if err != nil { if err != nil {
return nil, err return nil, err
} }
}
q.Params[strings.ToLower(keyStr)] = valStr q.Params[strings.ToLower(keyStr)] = valStr
@ -74,12 +77,14 @@ func New(query string) (*Query, error) {
} }
} }
valEnd = 0
onKey = true onKey = true
keyStart = i + 1 keyStart = i + 1
} else if query[i] == '=' { } else if query[i] == '=' {
onKey = false onKey = false
valStart = i + 1 valStart = i + 1
valEnd = 0
} else if onKey { } else if onKey {
keyEnd = i keyEnd = i
} else { } else {