File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
lib/src/main/kotlin/io/github/json5/kotlin Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments