Skip to content

Commit ea4616d

Browse files
authored
Broaden accepted values in non-urlencoded headers (#4132)
1 parent 8452f9a commit ea4616d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

opentelemetry-api/src/opentelemetry/util/re.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@
3232
# A value contains a URL-encoded UTF-8 string. The encoded form can contain any
3333
# printable US-ASCII characters (0x20-0x7f) other than SP, DEL, and ",;/
3434
_VALUE_FORMAT = r"[\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]*"
35+
# Like above with SP included
36+
_LIBERAL_VALUE_FORMAT = r"[\x20\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]*"
3537
# A key-value is key=value, with optional whitespace surrounding key and value
3638
_KEY_VALUE_FORMAT = rf"{_OWS}{_KEY_FORMAT}{_OWS}={_OWS}{_VALUE_FORMAT}{_OWS}"
3739

3840
_HEADER_PATTERN = compile(_KEY_VALUE_FORMAT)
3941
_LIBERAL_HEADER_PATTERN = compile(
40-
rf"{_OWS}{_KEY_FORMAT}{_OWS}={_OWS}[\w ]*{_OWS}"
42+
rf"{_OWS}{_KEY_FORMAT}{_OWS}={_OWS}{_LIBERAL_VALUE_FORMAT}{_OWS}"
4143
)
4244
_DELIMITER_PATTERN = compile(r"[ \t]*,[ \t]*")
4345

opentelemetry-api/tests/util/test_re.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ def test_parse_env_headers_liberal(self):
8989
inp = self._common_test_cases() + [
9090
# valid header value
9191
("key=value othervalue", [("key", "value othervalue")], False),
92+
(
93+
"key=value Other_Value==",
94+
[("key", "value Other_Value==")],
95+
False,
96+
),
9297
]
9398
for case_ in inp:
9499
headers, expected, warn = case_

0 commit comments

Comments
 (0)