Skip to content

Commit 2a373a2

Browse files
committed
Escape single-quotes in urls
This should fix #9
1 parent 592443c commit 2a373a2

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

background.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ browser = browser || chrome;
1111

1212
const menus = browser.menus || browser.contextMenus;
1313

14+
function createMpvSchemeURI(url) {
15+
return `mpv://watch#${url.replace(/'/g, "%27")}`;
16+
}
17+
1418
async function openInMpv(url) {
15-
const mpvUrl = `mpv://watch#${url}`;
19+
const mpvUrl = createMpvSchemeURI(url);
1620

1721
const alreadySavedDesktop = await localDesktopFileVersionIsCurrent();
1822
if (alreadySavedDesktop) {

open-in-mpv.plugin.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ const settings = {
1414
locallyInstalledVersion: null
1515
};
1616

17-
const MPVSchemePrefix = "mpv://watch#";
17+
function createMpvSchemeURI(url) {
18+
return `mpv://watch#${url.replace(/'/g, "%27")}`;
19+
}
1820

1921
function contextMenuPatch(tree, context) {
2022
const href = context.target.href || context.target.parentNode.href
@@ -28,14 +30,14 @@ function contextMenuPatch(tree, context) {
2830
console.log("open-in-mpv: link is " + href);
2931

3032
if (settings.locallyInstalledVersion && settings.locallyInstalledVersion >= desktopFileVersion) {
31-
const newWindow = window.open(MPVSchemePrefix + href, "_blank", "noopener noreferrer");
33+
const newWindow = window.open(createMpvSchemeURI(href), "_blank", "noopener noreferrer");
3234

3335
if (newWindow === null) { // is null because opens in external application
3436
BdApi.UI.showToast("" + href + " opened in mpv.", { type: "success" });
3537
console.log("open-in-mpv: success");
3638
} else {
3739
BdApi.UI.showToast("" + href + " failed to open in mpv.", { type: "error" });
38-
console.log(`open-in-mpv: failed to open ${MPVSchemePrefix}${href} in mpv.`);
40+
console.log(`open-in-mpv: failed to open ${createMpvSchemeURI(href)} in mpv.`);
3941
}
4042
} else {
4143
BdApi.UI.showConfirmationModal("Open in mpv",

0 commit comments

Comments
 (0)