headers: add negative unit tests

This commit is contained in:
aler9
2021-04-19 22:47:43 +02:00
parent be5df0f7f7
commit 49dfd34ede
2 changed files with 73 additions and 55 deletions

View File

@@ -6,15 +6,11 @@ import (
)
func findValue(str string, separator byte) (string, string, error) {
if str == "" {
return "", "", nil
}
if str[0] == '"' {
if len(str) > 0 && str[0] == '"' {
i := 1
for {
if i >= len(str) {
return "", "", fmt.Errorf("apices not closed (%v)", str)
return "", "", fmt.Errorf("apexes not closed (%v)", str)
}
if str[i] == '"' {
@@ -41,7 +37,7 @@ func keyValParse(str string, separator byte) (map[string]string, error) {
for len(str) > 0 {
i := strings.IndexByte(str, '=')
if i < 0 {
return nil, fmt.Errorf("unable to find key '%v'", str)
return nil, fmt.Errorf("unable to find key (%v)", str)
}
var k string
k, str = str[:i], str[i+1:]