-
Notifications
You must be signed in to change notification settings - Fork 275
Description
Describe the bug
The current code looks like this:
s := strings.Index(fwd, ", ")
if s == -1 {
s = len(fwd)
}
addr = fwd[:s]
As can be seen in this playground, it doesn't handle whitespace around the comma properly. (The playground isn't working consistently, I think because of back-end weirdness. But the code works.)
If the header is like 1.1.1.1,2.2.2.2, 3.3.3.3
, the resulting addr
will be 1.1.1.1,2.2.2.2
. If the header is like 1.1.1.1 , 2.2.2.2
, the resulting addr
will be 1.1.1.1<space>
.
RFC 2616 states that there can be "linear white space" (LWS; space or tab) around the values and commas. For example:
each separated by one or more commas (",") and OPTIONAL linear white space (LWS). This makes the usual form of lists very easy; a rule such as
( *LWS element *( *LWS "," *LWS element ))
And:
Except where noted otherwise, linear white space (LWS) can be included between any two adjacent words (token or quoted-string), and between adjacent words and separators, without changing the interpretation of a field.
I will submit a PR shortly.
Versions
go1.18
master HEAD
Steps to Reproduce
Code here: https://go.dev/play/p/uTO1eaTRsbx
Expected behavior
Proper handling of whitespace.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status