diff --git a/opentelemetry-api/src/opentelemetry/util/re.py b/opentelemetry-api/src/opentelemetry/util/re.py index bee1c61562e..2436cb6173e 100644 --- a/opentelemetry-api/src/opentelemetry/util/re.py +++ b/opentelemetry-api/src/opentelemetry/util/re.py @@ -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]*") diff --git a/opentelemetry-api/tests/util/test_re.py b/opentelemetry-api/tests/util/test_re.py index b3b4df46c59..7c0a2a388e3 100644 --- a/opentelemetry-api/tests/util/test_re.py +++ b/opentelemetry-api/tests/util/test_re.py @@ -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_