Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ddtrace/internal/_tagset.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
Tagset eBNF::

tagset = tag, { ",", tag };
tag = ( identifier - space ), "=", identifier;
identifier = { ? ASCII 32-126 ? - equal or comma };
tag = key, "=", value;
key = { ? ASCII 32-126 ? - equal or comma or space };
value = { ? ASCII 32-126 ? - comma };
equal or comma = "=" | ",";
space = " ";
"""
Expand Down Expand Up @@ -64,10 +65,9 @@ cdef inline int is_valid_key_char(int c):

# Same as is_valid_key_char except spaces are allowed
cdef inline int is_valid_value_char(int c):
# string.printable - ",="
# string.printable - ","
# 44 = ",""
# 61 = "="
return c == 32 or is_valid_key_char(c)
return c == 32 or is_equal(c) or is_valid_key_char(c)


cpdef dict decode_tagset_string(str tagset):
Expand Down
10 changes: 9 additions & 1 deletion tests/tracer/test_tagset.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
("key=value,", {"key": "value"}),
# Values can have spaces
("key=value can have spaces", {"key": "value can have spaces"}),
# Values can have equals
("key=value=value", {"key": "value=value"}),
# Remove leading/trailing spaces from values
("key= value can have spaces ", {"key": "value can have spaces"}),
# Non-space whitespace characters are allowed
Expand All @@ -41,6 +43,13 @@
"_dd.p.upstream_services=bWNudWx0eS13ZWI|0|1;dHJhY2Utc3RhdHMtcXVlcnk|2|4,_dd.p.hello=world",
{"_dd.p.upstream_services": "bWNudWx0eS13ZWI|0|1;dHJhY2Utc3RhdHMtcXVlcnk|2|4", "_dd.p.hello": "world"},
),
(
"_dd.p.upstream_services=bWNudWx0eS13ZWI===|0|1;dHJhY2Utc3RhdHMtcXVlcnk===|2|4,_dd.p.hello=world",
{
"_dd.p.upstream_services": "bWNudWx0eS13ZWI===|0|1;dHJhY2Utc3RhdHMtcXVlcnk===|2|4",
"_dd.p.hello": "world",
},
),
],
)
def test_decode_tagset_string(header, expected):
Expand All @@ -61,7 +70,6 @@ def test_decode_tagset_string(header, expected):
"=value",
# Extra leading comma
",key=value",
"key=value=value",
"key=value,=value",
"key=value,value",
# Spaces are not allowed in keys
Expand Down