Allow Content-Encoding header to have no whitespace#253
Allow Content-Encoding header to have no whitespace#253p8 wants to merge 1 commit intoMDA2AV:mainfrom
Conversation
|
/validate rails |
|
|
BennyFranciscus
left a comment
There was a problem hiding this comment.
Hey p8, good catch on the whitespace-less headers! 👍
One issue though — the fix still has awk '{print tolower($2)}' at the end of the pipe, but after the sed 's/^[^:]*: *//' strips the header name + colon, the remaining value (e.g. "gzip") becomes $1 not $2.
So with the current fix:
"content-encoding: gzip"→ sed →"gzip"→ awk$2= empty → FAIL"content-encoding:gzip"→ sed →"gzip"→ awk$2= empty → FAIL
Should be $1 instead of $2:
comp_encoding=$(echo "$comp_headers" | grep -i "^content-encoding:" | sed 's/^[^:]*:[[:space:]]*//' | tr -d '\\r' | awk '{print tolower($1)}' || true)Or simpler — keep the awk-only approach but make it handle both formats:
comp_encoding=$(echo "$comp_headers" | grep -i "^content-encoding:" | tr -d '\\r' | awk -F: '{gsub(/^[[:space:]]+/, "", $2); print tolower($2)}' || true)This uses : as the field separator so $2 is everything after the colon, then strips leading whitespace.
Some framework return headers without whitespace:
content-encoding:gzip
The `check_header` method already takes this into account, but the
encoding header check does not.
|
Ok, this is RFC valid. |
|
Hey @p8, the intent here is right but I think there's a bug in the sed+awk pipeline. After Simplest fix — either change comp_encoding=$(echo "$comp_headers" | grep -i "^content-encoding:" | sed 's/^[^:]*: *//' | tr -d '\\r' | awk '{print tolower($1)}' || true)Or skip sed entirely and use a more flexible awk delimiter: comp_encoding=$(echo "$comp_headers" | grep -i "^content-encoding:" | tr -d '\\r' | awk -F ":[[:space:]]*" '{print tolower($2)}' || true)The second approach handles both |
18db923 to
5ab12f0
Compare
BennyFranciscus
left a comment
There was a problem hiding this comment.
Looks good now 👍 The sed+awk pipe handles both cases cleanly.
Some framework return headers without whitespace:
The
check_headermethod already takes this into account, but the encoding header check does not.