Skip to content

ABNF of text format seems wrong #288

@Hakuyume

Description

@Hakuyume

https://github.com/prometheus/OpenMetrics/blob/main/specification/OpenMetrics.md#abnf is using escaped-string for help message.

According to python parser, we use a different rule for help message. In this rule, " is handled as a normal character.
https://github.com/prometheus/client_python/blob/92b23970f032cbc990aa0e501708c425708e51ea/prometheus_client/parser.py#L32-L41
The testdata also show that " is allowed as a normal character. For example, the following line cannot be parsed with escaped-string since the first \\ is handled as an escaped \ and the following " is handled as an unescaped special character.

Updating ABNF as follows solves this problem.

diff --git a/specification/OpenMetrics.md b/specification/OpenMetrics.md
index 5c1eac5..6deee2a 100644
--- a/specification/OpenMetrics.md
+++ b/specification/OpenMetrics.md
@@ -334,7 +334,7 @@ metricset = *metricfamily
 metricfamily = *metric-descriptor *metric
 
 metric-descriptor = HASH SP type SP metricname SP metric-type LF
-metric-descriptor =/ HASH SP help SP metricname SP escaped-string LF
+metric-descriptor =/ HASH SP help SP metricname SP help-escaped-string LF
 metric-descriptor =/ HASH SP unit SP metricname SP *metricname-char LF
 
 metric = *sample
@@ -404,6 +404,15 @@ escaped-char =/ BS normal-char
 
 ; Any unicode character, except newline, double quote, and backslash
 normal-char = %x00-09 / %x0B-21 / %x23-5B / %x5D-D7FF / %xE000-10FFFF
+
+help-escaped-string = *help-escaped-char
+
+help-escaped-char = help-normal-char
+help-escaped-char =/ BS ("n" / BS)
+help-escaped-char =/ BS help-normal-char
+
+; Any unicode character, except newline and backslash
+help-normal-char = %x00-09 / %x0B-5B / %x5D-D7FF / %xE000-10FFFF
 ~~~~
 
 ### Overall Structure

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions