Skip to content

model: fix DotsEscaping unescape of names containing "_dot_" - #994

Open
Rohilalala wants to merge 1 commit into
prometheus:mainfrom
Rohilalala:fix/unescape-dots-roundtrip
Open

Rohilalala wants to merge 1 commit into
prometheus:mainfrom
Rohilalala:fix/unescape-dots-roundtrip

Conversation

@Rohilalala

Copy link
Copy Markdown

UnescapeName(EscapeName(n, DotsEscaping), DotsEscaping) did not return n when n contains the text _dot_. The first ReplaceAll matched _dot_ starting at the second underscore of an escaped __:

  • a_dot_b → a__dot__b → a_._b (now a_dot_b)
  • http_dot_requests_total → http_._requests_total (now unchanged)

Unescaping now decodes __ and _dot_ in a single left-to-right pass with a strings.Replacer, the exact inverse of EscapeName. Names with nothing to decode still come back without an allocation. Some input EscapeName cannot produce, where _dot_ overlaps an underscore pair, now decodes left to right as well: a__dot_b gives a_dot_b (it used to give a_.b).

UnescapeName replaced every "_dot_" before collapsing "__", so the escaped
form of a name that literally contains "_dot_" was decoded wrongly:
"a_dot_b" escapes to "a__dot__b" and came back as "a_._b". Decode both
sequences in a single left-to-right pass with a strings.Replacer instead.

Signed-off-by: Aditya <205600203+Rohilalala@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

1 participant