nirvana parseAcceptTypes error
Closed this issue · 1 comments
zjj2wry commented
Is this a BUG REPORT or FEATURE REQUEST?:
Uncomment only one, leave it on its own line:
/kind bug
/kind feature
What happened:
debug to here:
func parseAcceptTypes(v string) ([]string, error) {
fmt.Println("parseAcceptTypes", v)
types := []string{}
factors := []float64{}
strs := strings.Split(v, ",")
for _, str := range strs {
str := strings.Trim(str, " ")
tf := strings.Split(str, ";")
types = append(types, tf[0])
factor := 1.0
if len(tf) == 2 {
qp := strings.Split(tf[1], "=")
q, err := strconv.ParseFloat(qp[1], 32)
if err != nil {
fmt.Println("strconv.ParseFloat(qp[1], 32)", err)
return nil, err
}
factor = q
}
factors = append(factors, factor)
}
if len(types) <= 1 {
return types, nil
}
// In most cases, bubble sort is enough.
// Can optimize here.
exchanged := true
for exchanged {
exchanged = false
for i := 1; i < len(factors); i++ {
if factors[i] > factors[i-1] {
types[i-1], types[i] = types[i], types[i-1]
factors[i-1], factors[i] = factors[i], factors[i-1]
exchanged = true
}
}
}
return types, nil
}
this is log
parseAcceptTypes text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
strconv.ParseFloat(qp[1], 32) strconv.ParseFloat: parsing "b3": invalid syntax
s.root.Match strconv.ParseFloat: parsing "b3": invalid syntax
use chrome will get this error, use safari will success. chrome will pass Accept Header v=b3
What you expected to happen:
How to reproduce it (as minimally and precisely as possible):
Anything else we need to know?:
zjj2wry commented
already fixed in master branch
/close