Skip to content

Commit fe7b7fb

Browse files
authored
Merge pull request #19 from rokoucha/fix-local-file-path
ローカルファイルのパスをどの環境でも動くように組み立てる・ファイル名に # が入っていても壊れないようにする
2 parents 42b4304 + 1e41d41 commit fe7b7fb

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/miraktest-local/components/FileSelector.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,20 @@ export const FileSelector: React.VFC<{
122122
if (dialog.canceled) {
123123
return
124124
}
125-
const path = dialog.filePaths.slice(0).shift()
125+
const path = dialog.filePaths.at(0)
126126
if (!path) {
127127
return
128128
}
129-
setFilePath("file://" + path)
129+
// Windows なら file:///C:\path\to\file.m2ts、Linux / Mac なら file:///path/to/file.m2ts になるように加工する。パスの要素それぞれに対してパーセントエンコードをする
130+
const url =
131+
"file:///" +
132+
path
133+
.replaceAll(/\\/g, "/")
134+
.split("/")
135+
.filter((p) => p !== "")
136+
.map((p) => encodeURIComponent(p))
137+
.join("/")
138+
setFilePath(url)
130139
}}
131140
>
132141
<File className="pointer-events-none" size="1.75rem" />

0 commit comments

Comments
 (0)