Skip to content

Commit 1393634

Browse files
fix(clipboard): URL-encode path segments in absolutePathToFileUrl
Encode each path segment with encodeURIComponent to handle special characters like # and ? that would otherwise be interpreted as URL fragment/query delimiters. Co-Authored-By: Christian <christian@bagerbach.com>
1 parent 05b4a26 commit 1393634

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/utilityObsidian.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -830,9 +830,13 @@ async function readBlobArrayBuffer(blob: Blob): Promise<ArrayBuffer> {
830830

831831
function absolutePathToFileUrl(absolutePath: string): string {
832832
const forwardSlashPath = absolutePath.replace(/\\/g, "/");
833-
const urlPath = forwardSlashPath.startsWith("/")
834-
? forwardSlashPath
835-
: `/${forwardSlashPath}`;
833+
const segments = forwardSlashPath.split("/");
834+
const encodedPath = segments
835+
.map((segment) => encodeURIComponent(segment))
836+
.join("/");
837+
const urlPath = encodedPath.startsWith("/")
838+
? encodedPath
839+
: `/${encodedPath}`;
836840
return `file://${urlPath}`;
837841
}
838842

0 commit comments

Comments
 (0)