@@ -1398,6 +1398,7 @@ func TestFirstForwardedProto(t *testing.T) {
13981398 want string
13991399 }{
14001400 {name : "empty" , value : "" , want : "" },
1401+ {name : "whitespace only" , value : " \t " , want : "" },
14011402 {name : "proto only" , value : "proto=https" , want : "https" },
14021403 {name : "spaces around separators" , value : " for = 192.0.2.1 ; proto = https " , want : "https" },
14031404 {name : "quoted with escapes yields valid proto" , value : `proto="ht\tps"` , want : "https" },
@@ -1408,6 +1409,17 @@ func TestFirstForwardedProto(t *testing.T) {
14081409 {name : "ipv6 for with proto" , value : `for="[2001:db8::1]:4711";proto=https` , want : "https" },
14091410 {name : "proto in second element only" , value : "for=_hidden, for=192.0.2.1;proto=http" , want : "http" },
14101411 {name : "invalid then valid" , value : "proto=ftp, for=1.2.3.4;proto=https" , want : "https" },
1412+ // branch coverage for parser edge paths
1413+ {name : "leading quoted garbage then proto" , value : `"not-a-param";proto=https` , want : "https" },
1414+ {name : "quoted garbage with escapes then proto" , value : `"a\"b";proto=wss` , want : "wss" },
1415+ {name : "name without equals then valid" , value : "for;proto=https" , want : "https" },
1416+ {name : "equals without name then proto" , value : "=ignored;proto=http" , want : "http" },
1417+ {name : "unclosed quote does not hang" , value : `proto="https` , want : "https" },
1418+ {name : "backslash at end of quoted value" , value : `proto="https\` , want : "https" },
1419+ {name : "trailing OWS after value" , value : "proto=https \t ;for=1.2.3.4" , want : "https" },
1420+ {name : "only separators" , value : ",,,;;;" , want : "" },
1421+ {name : "non token garbage then proto" , value : "@@@;proto=ws" , want : "ws" },
1422+ {name : "token-like custom param" , value : "x.y_z=1;proto=https" , want : "https" },
14111423 }
14121424 for _ , tc := range tests {
14131425 t .Run (tc .name , func (t * testing.T ) {
@@ -1416,6 +1428,15 @@ func TestFirstForwardedProto(t *testing.T) {
14161428 }
14171429}
14181430
1431+ func TestIsTokenChar (t * testing.T ) {
1432+ for _ , b := range []byte ("!#$%&'*+-.^_`|~09AZaz" ) {
1433+ assert .True (t , isTokenChar (b ), "expected token char %q" , b )
1434+ }
1435+ for _ , b := range []byte (" \t ,;=\" <>()[]{}\\ /" ) {
1436+ assert .False (t , isTokenChar (b ), "expected non-token char %q" , b )
1437+ }
1438+ }
1439+
14191440func TestContext_IsWebSocket (t * testing.T ) {
14201441 tests := []struct {
14211442 c * Context
0 commit comments