Skip to content

Commit

Permalink
Broaden accepted values in non-urlencoded headers (open-telemetry#4132)
Browse files Browse the repository at this point in the history
  • Loading branch information
xrmx authored Aug 19, 2024
1 parent 8452f9a commit ea4616d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion opentelemetry-api/src/opentelemetry/util/re.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
# A value contains a URL-encoded UTF-8 string. The encoded form can contain any
# printable US-ASCII characters (0x20-0x7f) other than SP, DEL, and ",;/
_VALUE_FORMAT = r"[\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]*"
# Like above with SP included
_LIBERAL_VALUE_FORMAT = r"[\x20\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]*"
# A key-value is key=value, with optional whitespace surrounding key and value
_KEY_VALUE_FORMAT = rf"{_OWS}{_KEY_FORMAT}{_OWS}={_OWS}{_VALUE_FORMAT}{_OWS}"

_HEADER_PATTERN = compile(_KEY_VALUE_FORMAT)
_LIBERAL_HEADER_PATTERN = compile(
rf"{_OWS}{_KEY_FORMAT}{_OWS}={_OWS}[\w ]*{_OWS}"
rf"{_OWS}{_KEY_FORMAT}{_OWS}={_OWS}{_LIBERAL_VALUE_FORMAT}{_OWS}"
)
_DELIMITER_PATTERN = compile(r"[ \t]*,[ \t]*")

Expand Down
5 changes: 5 additions & 0 deletions opentelemetry-api/tests/util/test_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ def test_parse_env_headers_liberal(self):
inp = self._common_test_cases() + [
# valid header value
("key=value othervalue", [("key", "value othervalue")], False),
(
"key=value Other_Value==",
[("key", "value Other_Value==")],
False,
),
]
for case_ in inp:
headers, expected, warn = case_
Expand Down

0 comments on commit ea4616d

Please sign in to comment.