fix(serde-hjson): Fix bug with slashes embedded in block comments
This commit is contained in:
@@ -423,6 +423,8 @@ public class HjsonLexer implements AutoCloseable {
|
||||
lastWasAsterisk = true;
|
||||
} else if (lastWasAsterisk && codePoint == '/') {
|
||||
break;
|
||||
} else {
|
||||
lastWasAsterisk = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user