Skip to content

fix: use double-quoted Spotlight query for mdfind app names#7464

Merged
Jasonnnz merged 1 commit into
feature/qa-video-automationfrom
swarm/fb2-7456
Feb 24, 2026
Merged

fix: use double-quoted Spotlight query for mdfind app names#7464
Jasonnnz merged 1 commit into
feature/qa-video-automationfrom
swarm/fb2-7456

Conversation

@Jasonnnz
Copy link
Copy Markdown
Contributor

@Jasonnnz Jasonnnz commented Feb 24, 2026

Switches mdfind query value from single-quoted with shell-style escaping to double-quoted with proper escaping, since Process.arguments bypasses the shell. Addresses feedback from #7456.

Summary

  • Process.arguments passes arguments directly to the executable without shell interpretation, so the POSIX shell idiom '\'' for escaping single quotes was being passed raw to mdfind, breaking Spotlight query parsing.
  • Switched the kMDItemDisplayName comparison value to use double quotes with proper double-quote escaping instead.

Test plan

  • Build the macOS app with ./build.sh
  • Test app lookup with mdfind for apps with standard names (e.g., "Safari", "Terminal")
  • Test app lookup for apps with special characters in names (e.g., names containing quotes)

🤖 Generated with Claude Code


Open with Devin

Process.arguments bypasses the shell, so the shell-style single-quote
escaping ('\'') was passed raw to mdfind, breaking Spotlight query
parsing. Switch to double-quoted query values with proper double-quote
escaping instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Jasonnnz Jasonnnz merged commit c11b38c into feature/qa-video-automation Feb 24, 2026
@Jasonnnz Jasonnnz deleted the swarm/fb2-7456 branch February 24, 2026 02:42
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

// double quotes. Process.arguments bypasses the shell, so shell-style
// single-quote escaping (e.g. '\'') would be passed raw to mdfind and
// break Spotlight query parsing.
let sanitizedName = name.replacingOccurrences(of: "\"", with: "\\\"")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Missing backslash escaping in mdfind query allows malformed Spotlight queries

The sanitization on line 388 only escapes double quotes but not backslashes. Since mdfind's Spotlight query parser treats \ as an escape character inside double-quoted strings, an app name containing a backslash will produce a malformed query.

Root Cause and Example

If name is foo\ (contains a literal backslash), the sanitized name is still foo\ (no replacement occurs), and the query becomes:

kMDItemKind == 'Application' && kMDItemDisplayName == "foo\"

Here \" is interpreted by mdfind as an escaped double quote, so the string literal is never terminated and the query is malformed. This causes mdfind to fail (exit non-zero), and the function returns nil.

More critically, a name like foo\"bar would have its " escaped to \", producing foo\\\"bar in the query — but the original backslash isn't escaped, so mdfind sees foo\"bar where \" is an escaped quote, breaking the intended string boundary.

Backslashes must be escaped before double quotes to ensure correct nesting:

let sanitizedName = name
    .replacingOccurrences(of: "\\", with: "\\\\")
    .replacingOccurrences(of: "\"", with: "\\\"")

Impact: While app names with backslashes are extremely rare on macOS, this is an incomplete fix for the escaping problem the PR is trying to solve. The function degrades gracefully (returns nil), so the impact is limited to a failed lookup rather than a crash.

Suggested change
let sanitizedName = name.replacingOccurrences(of: "\"", with: "\\\"")
let sanitizedName = name.replacingOccurrences(of: "\\", with: "\\\\").replacingOccurrences(of: "\"", with: "\\\"")
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Jasonnnz pushed a commit that referenced this pull request Feb 24, 2026
Addresses review feedback on PR #7464: the sanitization only escaped
double quotes but not backslashes. Since Spotlight's query parser treats
`\` as an escape character inside double-quoted strings, an app name
containing a backslash would produce a malformed query. Escape
backslashes before double quotes to ensure correct nesting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Jasonnnz added a commit that referenced this pull request Feb 24, 2026
Addresses review feedback on PR #7464: the sanitization only escaped
double quotes but not backslashes. Since Spotlight's query parser treats
`\` as an escape character inside double-quoted strings, an app name
containing a backslash would produce a malformed query. Escape
backslashes before double quotes to ensure correct nesting.

Co-authored-by: Vellum Assistant <assistant@vellum.ai>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant