From 6653813cb99035a00587016d1202dec627653440 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 17 Dec 2025 11:36:51 +0100 Subject: [PATCH] fix(macos): avoid treating '/' as file target --- apps/macos/Sources/Clawdis/CanvasManager.swift | 10 +++++++--- apps/macos/Sources/Clawdis/CanvasWindow.swift | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/macos/Sources/Clawdis/CanvasManager.swift b/apps/macos/Sources/Clawdis/CanvasManager.swift index 0abc245160..60d68829e5 100644 --- a/apps/macos/Sources/Clawdis/CanvasManager.swift +++ b/apps/macos/Sources/Clawdis/CanvasManager.swift @@ -116,9 +116,13 @@ final class CanvasManager { if scheme == "https" || scheme == "http" || scheme == "file" { return url } } - // Convenience: existing absolute paths resolve as local files. - if trimmed.hasPrefix("/"), FileManager.default.fileExists(atPath: trimmed) { - return URL(fileURLWithPath: trimmed) + // Convenience: existing absolute *file* paths resolve as local files. + // (Avoid treating Canvas routes like "/" as filesystem paths.) + if trimmed.hasPrefix("/") { + var isDir: ObjCBool = false + if FileManager.default.fileExists(atPath: trimmed, isDirectory: &isDir), !isDir.boolValue { + return URL(fileURLWithPath: trimmed) + } } return nil diff --git a/apps/macos/Sources/Clawdis/CanvasWindow.swift b/apps/macos/Sources/Clawdis/CanvasWindow.swift index b7cd14c1ce..9e0021f9b7 100644 --- a/apps/macos/Sources/Clawdis/CanvasWindow.swift +++ b/apps/macos/Sources/Clawdis/CanvasWindow.swift @@ -140,12 +140,16 @@ final class CanvasWindowController: NSWindowController, WKNavigationDelegate, NS } } - // Convenience: absolute paths resolve as local files when they exist. - if trimmed.hasPrefix("/"), FileManager.default.fileExists(atPath: trimmed) { + // Convenience: absolute file paths resolve as local files when they exist. + // (Avoid treating Canvas routes like "/" as filesystem paths.) + if trimmed.hasPrefix("/") { + var isDir: ObjCBool = false + if FileManager.default.fileExists(atPath: trimmed, isDirectory: &isDir), !isDir.boolValue { let url = URL(fileURLWithPath: trimmed) canvasWindowLogger.debug("canvas load file \(url.absoluteString, privacy: .public)") self.loadFile(url) return + } } guard let url = CanvasScheme.makeURL(