Skip to content

Commit 5f677a3

Browse files
committed
Fix: last quotation mark of string next string
The lexer wasn't skipping the last quotation mark of a string, which meant that this quotation mark was being considered as the start of a second string. This resulted in exceptions that the string wasn't terminated if a second token was requested for simple strings like "\"test\""
1 parent 22e3998 commit 5f677a3

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/main/kotlin/lexer/StringJSONLexer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class StringJSONLexer(private val content: CharSequence) : JSONLexer {
7777
throw LexerException("String wasn't terminated") // TODO: Better error handling
7878
}
7979

80+
position++
81+
8082
return JSONLexeme(JSONLexemeType.STRING, builder.toString())
8183
}
8284

src/test/kotlin/lexer/StringJSONLexerTest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ class StringJSONLexerTest {
7777
val inputs = arrayOf("\"\"", "\"Hello World\"")
7878

7979
inputs.forEach {
80-
assertEquals(JSONLexeme(JSONLexemeType.STRING, it.substring(1, it.length - 1)), StringJSONLexer(it).getNext())
80+
val lexer = StringJSONLexer(it)
81+
assertEquals(JSONLexeme(JSONLexemeType.STRING, it.substring(1, it.length - 1)), lexer.getNext())
82+
assertEquals(JSONLexeme(JSONLexemeType.EOF), lexer.getNext())
8183

8284
// Add padding
8385
assertEquals(JSONLexeme(JSONLexemeType.STRING, it.substring(1, it.length - 1)), StringJSONLexer(" \t$it").getNext())

0 commit comments

Comments
 (0)