Skip to content

Commit

Permalink
Add: escape ff127 option (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
eight04 authored Aug 12, 2024
1 parent 97df0a6 commit 75d12d0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ If you find that the filename includes an emoji and the browser can't save the i

See also: [#175](https://github.com/eight04/image-picka/issues/175)

Illegal filename bug in Firefox 127
----------------------------------

There is a bug in Firefox 127 that throws an error when downloading a file with a filename that contains a percentage, spaces, or dot.

See also: [#347](https://github.com/eight04/image-picka/issues/347)

Translation
-----------

Expand Down
13 changes: 11 additions & 2 deletions src/lib/escape.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,16 @@ function trimString(s) {
}

export function escapePath(path) {
return path.split(/\\|\//g).map(component =>
trimString(component).replace(/^\.+|\.+$/g, m => ".".repeat(m.length))
const parts = path.split(/\\|\//g);
return parts.map((component, i) => {
component = trimString(component).replace(/^\.+|\.+$/g, m => ".".repeat(m.length))
if (pref.get("escapeFF127")) {
component = component.replace(/%/g, "%");
if (i < parts.length - 1) {
component = component.replace(/\./g, ".");
}
}
return component;
}
).join("/");
}
11 changes: 11 additions & 0 deletions src/lib/pref.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const DEFAULT = {
downloadButtonPositionVertical: "TOP_OUTSIDE",
escapeWithUnicode: true,
escapeZWJ: false,
escapeFF127: shouldEscapeFF127(),
isolateTabs: false,
filenameConflictAction: "uniquify",
saveAs: false,
Expand Down Expand Up @@ -87,3 +88,13 @@ async function init() {
await Promise.all(pending);
await browser.storage.local.set({prefInSync: true});
}

function shouldEscapeFF127() {
const ua = navigator.userAgent;
const isFirefox = /Firefox/.test(ua);
if (!isFirefox) {
return false;
}
const version = ua.match(/Firefox\/(\d+)/)[1];
return parseInt(version, 10) >= 127;
}
6 changes: 6 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ const root = createUI({
label: _("optionEscapeZWJLabel"),
learnMore: "https://github.com/eight04/image-picka#zero-width-joiner"
},
{
type: "checkbox",
key: "escapeFF127",
label: _("optionEscapeFF127Label"),
learnMore: "https://github.com/eight04/image-picka#illegal-filename-bug-in-firefox-127"
},
{
type: "text",
key: "srcAlternative",
Expand Down
4 changes: 4 additions & 0 deletions src/static/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@
"message": "Button size",
"description": "Label of downloadButtonSize option"
},
"optionEscapeFF127Label": {
"message": "Escape dot and percentage in the filename to avoid Firefox 127 bug.",
"description": "Label of escapeFF127 option"
},
"optionEscapeWithUnicodeLabel": {
"message": "Escape special characters into Unicode glyphs.",
"description": "Label of escapeWithUnicode option"
Expand Down

0 comments on commit 75d12d0

Please sign in to comment.