Files
wehub-resource-sync 48b3ccf279
gitleaks / gitleaks (push) Has been skipped
Test / test (ubuntu-latest) (push) Failing after 0s
Test / test (windows-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:12:29 +08:00

35 lines
731 B
Go

package codec
// decodePercent decodes percent encoded strings
func decodePercent(encodedValue string) string {
encLen := len(encodedValue)
decodedValue := make([]byte, encLen)
decIndex := 0
encIndex := 0
for encIndex < encLen {
if encodedValue[encIndex] == '%' && encIndex+2 < encLen {
n1 := hexMap[encodedValue[encIndex+1]]
n2 := hexMap[encodedValue[encIndex+2]]
// Make sure they're hex characters
if n1|n2 != '\xff' {
b := n1<<4 | n2
if !printableASCII[b] {
return ""
}
decodedValue[decIndex] = b
encIndex += 3
decIndex += 1
continue
}
}
decodedValue[decIndex] = encodedValue[encIndex]
encIndex += 1
decIndex += 1
}
return string(decodedValue[:decIndex])
}