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;
|
lastWasAsterisk = true;
|
||||||
} else if (lastWasAsterisk && codePoint == '/') {
|
} else if (lastWasAsterisk && codePoint == '/') {
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
lastWasAsterisk = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package de.siphalor.tweed5.data.hjson;
|
package de.siphalor.tweed5.data.hjson;
|
||||||
|
|
||||||
|
import lombok.SneakyThrows;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.Timeout;
|
import org.junit.jupiter.api.Timeout;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
@@ -128,6 +129,28 @@ class HjsonLexerTest {
|
|||||||
assertGeneralEof(lexer, new HjsonReadPosition(1, input.length() + 1));
|
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) {
|
private HjsonLexer createLexer(String input) {
|
||||||
return new HjsonLexer(new StringReader(input));
|
return new HjsonLexer(new StringReader(input));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user