fix: prevent crash in parseNotificationPayload when fields are empty (#881)
Swift's split(separator:) omits empty subsequences by default, so a payload like "||" or "||body" produces an empty or misaligned array. Accessing parts[0] unconditionally then triggers an out-of-bounds trap (EXC_BREAKPOINT / SIGTRAP). Two changes: 1. Pass omittingEmptySubsequences: false to preserve field positions across the pipe delimiters, so "title||body" correctly yields ["title", "", "body"] instead of ["title", "body"]. 2. Guard parts[0] with a bounds check, consistent with how parts[1] and parts[2] are already accessed. Reproduces when cmux notify is called with empty --title or via Claude Code's Notification hook where env vars may be empty.
This commit is contained in:
parent
b07532c522
commit
5baf0d1a3b
1 changed files with 2 additions and 2 deletions
|
|
@ -10837,8 +10837,8 @@ class TerminalController {
|
|||
private func parseNotificationPayload(_ args: String) -> (String, String, String) {
|
||||
let trimmed = args.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmed.isEmpty else { return ("Notification", "", "") }
|
||||
let parts = trimmed.split(separator: "|", maxSplits: 2).map(String.init)
|
||||
let title = parts[0].trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let parts = trimmed.split(separator: "|", maxSplits: 2, omittingEmptySubsequences: false).map(String.init)
|
||||
let title = parts.count > 0 ? parts[0].trimmingCharacters(in: .whitespacesAndNewlines) : ""
|
||||
let subtitle = parts.count > 2 ? parts[1].trimmingCharacters(in: .whitespacesAndNewlines) : ""
|
||||
let body = parts.count > 2
|
||||
? parts[2].trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue