Duansg commented on PR #3752:
URL: https://github.com/apache/hertzbeat/pull/3752#issuecomment-3262359409
> Problem description, for reference and to reproduce the issue
` item_create_total{app="item-microservi\"ce-center",value="agent"} 0.0`
```
private static CharChecker parseLabelValue(InputStream inputStream,
StringBuilder stringBuilder) throws IOException, FormatException {
int i = getChar(inputStream);
while (i != '"' && i != -1) {
if (i == '\\') {
i = getChar(inputStream);
switch (i) {
case 'n' -> stringBuilder.append('\n');
case '\\' -> stringBuilder.append('\\');
case '\"' -> stringBuilder.append('\"');
default -> {
// Unknown escape, keep as-is
//
https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/lib/protoparser/prometheus/parser.go#L419
stringBuilder.append('\\');
if (i != -1) {
stringBuilder.append((char) i);
}
}
}
} else {
stringBuilder.append((char) i);
}
i = getChar(inputStream);
}
return new CharChecker(i);
}
private static int getChar(InputStream inputStream) throws IOException,
FormatException {
int i = inputStream.read(); // read '\'
if (i == '\\') { // hit
i = inputStream.read(); // read
next '\''
if (escapeMap.containsKey(i)) { //
escapeMap hit
return escapeMap.get(i); // return
'\"' -> i , The lower-level condition
while (i
!= '"' && i != -1) exits the loop, causing the tag to be truncated.
} else {
throw new FormatException("Escape character failed.");
}
} else {
return i;
}
}
```
`item_create3_total{app1_="item-microservi\\ce-center",value="agent"} 0.0`
```
private static CharChecker parseLabelValue(InputStream inputStream,
StringBuilder stringBuilder) throws IOException, FormatException {
int i = getChar(inputStream);
while (i != '"' && i != -1) {
if (i == '\\') { // hit'\'
i = getChar(inputStream);
switch (i) {
case 'n' -> stringBuilder.append('\n');
case '\\' -> stringBuilder.append('\\');
case '\"' -> stringBuilder.append('\"');
default -> {
// Unknown escape, keep as-is
//
https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/lib/protoparser/prometheus/parser.go#L419
stringBuilder.append('\\');
if (i != -1) {
stringBuilder.append((char) i);
}
}
}
} else {
stringBuilder.append((char) i);
}
i = getChar(inputStream); // read
the first'\'
}
return new CharChecker(i);
}
private static int getChar(InputStream inputStream) throws IOException,
FormatException {
int i = inputStream.read(); // read the
second '\'
if (i == '\\') { // hit the
second'\'
i = inputStream.read(); // read 'c'
if (escapeMap.containsKey(i)) { //
escapeMap miss
return escapeMap.get(i);
} else { // throw
error
throw new FormatException("Escape character failed.");
}
} else {
return i;
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]