Skip to content

Commit ce071d6

Browse files
committed
All test pass
1 parent c80414b commit ce071d6

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/src/main/kotlin/io/github/json5/kotlin/JSON5Lexer.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,6 @@ class JSON5Lexer(private val source: String) {
762762
val buffer = StringBuilder()
763763

764764
// Handle the case where the first character is already processed
765-
// (e.g., when called from the main switch statement)
766765
if (currentChar != null && isIdentifierStart(currentChar)) {
767766
buffer.append(currentChar)
768767
advance()
@@ -797,7 +796,19 @@ class JSON5Lexer(private val source: String) {
797796
buffer.append(currentChar)
798797
advance()
799798
} else {
800-
break
799+
// Special handling for malformed literals - check if this might be a truncated literal
800+
val ident = buffer.toString()
801+
if ((ident == "t" || ident == "tr" || ident == "tru") && currentChar != null) {
802+
// This looks like a malformed "true" literal
803+
throw JSON5Exception.invalidChar(currentChar!!, line, column)
804+
} else if ((ident == "f" || ident == "fa" || ident == "fal" || ident == "fals") && currentChar != null) {
805+
// This looks like a malformed "false" literal
806+
throw JSON5Exception.invalidChar(currentChar!!, line, column)
807+
} else if ((ident == "n" || ident == "nu" || ident == "nul") && currentChar != null) {
808+
// This looks like a malformed "null" literal
809+
throw JSON5Exception.invalidChar(currentChar!!, line, column)
810+
}
811+
break;
801812
}
802813
}
803814

0 commit comments

Comments
 (0)