Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tmux-corpus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
done

terminal-nightly:
if: github.event_name == 'schedule'
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
runs-on: [self-hosted, warp-macos-15-arm64-6x]
timeout-minutes: 30
steps:
Expand Down
16 changes: 12 additions & 4 deletions Sources/JSONCParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ enum JSONCParser {
}
}

static func isLineTerminator(_ character: Character) -> Bool {
// Swift treats "\r\n" as a single extended grapheme cluster, so comparing
// against "\n" alone misses CRLF line endings and would let line comments
// run to end-of-file. Match any character whose first scalar is CR or LF.
guard let scalar = character.unicodeScalars.first else { return false }
return scalar == "\n" || scalar == "\r"
}

private static func stripComments(from source: String) throws -> String {
var result = ""
var index = source.startIndex
Expand Down Expand Up @@ -112,7 +120,7 @@ enum JSONCParser {
let next = source[nextIndex]
if next == "/" {
index = source.index(after: nextIndex)
while index < source.endIndex && source[index] != "\n" {
while index < source.endIndex && !JSONCParser.isLineTerminator(source[index]) {
index = source.index(after: index)
}
continue
Expand Down Expand Up @@ -355,7 +363,7 @@ enum JSONCObjectEditor {
let next = source.index(after: index)
if next < source.endIndex, source[next] == "/" {
index = source.index(after: next)
while index < source.endIndex, source[index] != "\n" {
while index < source.endIndex, !JSONCParser.isLineTerminator(source[index]) {
index = source.index(after: index)
}
continue
Expand Down Expand Up @@ -452,7 +460,7 @@ enum JSONCObjectEditor {
let next = source.index(after: index)
if next < source.endIndex, source[next] == "/" {
index = source.index(after: next)
while index < source.endIndex, source[index] != "\n" {
while index < source.endIndex, !JSONCParser.isLineTerminator(source[index]) {
index = source.index(after: index)
}
continue
Expand Down Expand Up @@ -483,7 +491,7 @@ enum JSONCObjectEditor {
var lineStart = index
while lineStart > source.startIndex {
let previous = source.index(before: lineStart)
if source[previous] == "\n" || source[previous] == "\r" {
if JSONCParser.isLineTerminator(source[previous]) {
break
}
lineStart = previous
Expand Down
Loading