Skip to content
Open
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
5 changes: 2 additions & 3 deletions prometheus_client/openmetrics/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,9 @@ def _parse_remaining_text(text):
state = 'timestamp'
text = split_text[1]

it = iter(text)
in_quotes = False
for char in it:
if char == '"':
for i, char in enumerate(text):
if char == '"' and not _is_character_escaped(text, i):
in_quotes = not in_quotes
if in_quotes:
continue
Expand Down
11 changes: 11 additions & 0 deletions tests/openmetrics/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,17 @@ def test_label_escaping(self):
metric_family.add_metric([unescaped_val, "baz"], 1)
self.assertEqual([metric_family], list(families))

def test_exemplar_label_escaping(self):
for escaped_val, unescaped_val in [('\\"', '"'), ('\\\\', '\\'), ('\\\\\\"', '\\"')]:
families = list(text_string_to_metric_families("""# TYPE a counter
# HELP a help
a_total 1 # {foo="%s"} 1
# EOF
""" % escaped_val))
metric_family = CounterMetricFamily("a", "help")
metric_family.add_sample("a_total", {}, 1.0, None, Exemplar({"foo": unescaped_val}, 1))
self.assertEqual([metric_family], list(families))

def test_help_escaping(self):
for escaped_val, unescaped_val in [
('foo', 'foo'),
Expand Down