Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: escape ff127 option #353

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading