Skip to content

Commit b3fbbca

Browse files
authored
Fix issue parsing double spaces after # HELP/# TYPE (#1134)
A regression was reported for 0.22.x where if there are two spaces after HELP or TEXT we would raise a value error. This was caused by having an extra entry in our array of splits due to how we preocess the splits. Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
1 parent 47d2b41 commit b3fbbca

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

prometheus_client/parser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ def _split_quoted(text, separator, maxsplit=0):
186186
tokens[-1] = text[x:]
187187
x = len(text)
188188
continue
189+
# If the first character is the separator keep going. This happens when
190+
# there are double whitespace characters separating symbols.
191+
if split_pos == x:
192+
x += 1
193+
continue
194+
189195
if maxsplit > 0 and len(tokens) > maxsplit:
190196
tokens[-1] = text[x:]
191197
break

tests/test_parser.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ def test_blank_lines_and_comments(self):
121121
""")
122122
self.assertEqualMetrics([CounterMetricFamily("a", "help", value=1)], list(families))
123123

124-
125124
def test_comments_parts_are_not_validated_against_legacy_metric_name(self):
126125
# https://github.com/prometheus/client_python/issues/1108
127126
families = text_string_to_metric_families("""
@@ -130,7 +129,12 @@ def test_comments_parts_are_not_validated_against_legacy_metric_name(self):
130129
""")
131130
self.assertEqualMetrics([], list(families))
132131

133-
132+
def test_extra_whitespace(self):
133+
families = text_string_to_metric_families("""# TYPE a counter
134+
# HELP a help
135+
a 1
136+
""")
137+
self.assertEqualMetrics([CounterMetricFamily("a", "help", value=1)], list(families))
134138

135139
def test_tabs(self):
136140
families = text_string_to_metric_families("""#\tTYPE\ta\tcounter

0 commit comments

Comments
 (0)