Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ABNF of text format seems wrong #288

Open
Hakuyume opened this issue Dec 12, 2024 · 0 comments
Open

ABNF of text format seems wrong #288

Hakuyume opened this issue Dec 12, 2024 · 0 comments

Comments

@Hakuyume
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant