fix(serde-hjson): Fix bug with slashes embedded in block comments

This commit is contained in:
2025-11-08 12:28:19 +01:00
parent 369ffdb57a
commit 28a8b56ce3
2 changed files with 26 additions and 1 deletions

View File

@@ -423,6 +423,8 @@ public class HjsonLexer implements AutoCloseable {
lastWasAsterisk = true;
} else if (lastWasAsterisk && codePoint == '/') {
break;
} else {
lastWasAsterisk = false;
}
}
}

View File

@@ -1,5 +1,6 @@
package de.siphalor.tweed5.data.hjson;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.params.ParameterizedTest;
@@ -128,6 +129,28 @@ class HjsonLexerTest {
assertGeneralEof(lexer, new HjsonReadPosition(1, input.length() + 1));
}
@ParameterizedTest
@CsvSource(textBlock = """
'// 123
true', TRUE
'# hash comments are cool
false', FALSE
'/*
multiline
comment
*/456', NUMBER
'/* multiline comment
* with/slashes
*/456', NUMBER
""")
@SneakyThrows
void chompComment(String input, HjsonLexerToken.Type tokenType) {
HjsonLexer lexer = createLexer(input);
HjsonLexerToken token = lexer.nextGeneralToken();
assertEquals(tokenType, token.type());
}
private HjsonLexer createLexer(String input) {
return new HjsonLexer(new StringReader(input));
}
@@ -138,4 +161,4 @@ class HjsonLexerTest {
assertDoesNotThrow(lexer::nextGeneralToken)
);
}
}
}