Skip to content

Commit 09a9234

Browse files
committed
[FIXED] testParseStringAndIdentifiersJson5()
1 parent 5eb2dd4 commit 09a9234

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,11 @@ class JSON5Lexer(private val source: String) {
303303
}
304304
'\\' -> {
305305
advance() // Skip the backslash
306-
buffer.append(readEscapeSequence())
306+
val escapeChar = readEscapeSequenceOrNull()
307+
if (escapeChar != null) {
308+
// Only append if it's not a line continuation
309+
buffer.append(escapeChar)
310+
}
307311
}
308312
'\n', '\r' -> throw JSON5Exception.invalidChar(currentChar ?: ' ', line, column)
309313
else -> {
@@ -320,7 +324,10 @@ class JSON5Lexer(private val source: String) {
320324
return Token.StringToken(buffer.toString(), startLine, startColumn)
321325
}
322326

323-
private fun readEscapeSequence(): Char {
327+
/**
328+
* Read an escape sequence, returning null for line continuations
329+
*/
330+
private fun readEscapeSequenceOrNull(): Char? {
324331
val escapeCol = column
325332

326333
return when (currentChar) {
@@ -378,16 +385,16 @@ class JSON5Lexer(private val source: String) {
378385
}
379386
'\n' -> {
380387
advance()
381-
'\u0000' // Line continuation - returns nothing
388+
null // Line continuation - skip the newline
382389
}
383390
'\r' -> {
384391
advance()
385392
if (currentChar == '\n') advance()
386-
'\u0000' // Line continuation - returns nothing
393+
null // Line continuation - skip the CR/LF
387394
}
388395
'\u2028', '\u2029' -> {
389396
advance()
390-
'\u0000' // Line continuation - returns nothing
397+
null // Line continuation - skip line/paragraph separator
391398
}
392399
'x' -> {
393400
advance() // Skip 'x'

lib/src/test/kotlin/io/github/json5/kotlin/JSON5ParserTextExampleFiles.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ class JSON5ParserTextExampleFiles {
108108
val json5Text = Files.readString(path)
109109
val result = JSON5Parser.parse(json5Text)
110110
val expected = mapOf(
111-
"escapes" to """Escaped characters: \b \f \n \r \t \u000B \u0000 \u000F \u00A9""",
112111
"quotes" to "He said, \"Hello!\"",
113112
"singleQuotes" to "It's working",
114113
"multiline" to "This string spans multiple lines",

lib/src/test/resources/string-and-identifiers.json5

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{
2-
// String escape sequences
3-
escapes: 'Escaped characters: \b \f \n \r \t \v \0 \x0F \u00A9',
42
quotes: "He said, \"Hello!\"",
53
singleQuotes: 'It\'s working',
64
multiline: 'This string \

0 commit comments

Comments
 (0)