single-file-core 1.2.25 → 1.2.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,6 +28,7 @@ import { parse } from "./template-parser.js";
28
28
  // eslint-disable-next-line quotes
29
29
  const DEFAULT_REPLACED_CHARACTERS = ["~", "+", "\\\\", "?", "%", "*", ":", "|", '"', "<", ">", "\x00-\x1f", "\x7F"];
30
30
  const DEFAULT_REPLACEMENT_CHARACTER = "_";
31
+ const REGEXP_ESCAPE = /([{}()^$&.*?/+|[\\\\]|\]|-)/g;
31
32
 
32
33
  const EMOJI_NAMES = {
33
34
  "😀": "grinning-face",
@@ -16867,7 +16868,7 @@ export { formatFilename, evalTemplate };
16867
16868
  async function formatFilename(content, doc, options, util) {
16868
16869
  let filename = (await evalTemplate(options.filenameTemplate, options, util, content, doc)) || "";
16869
16870
  if (options.replaceEmojisInFilename) {
16870
- EMOJIS.forEach(emoji => (filename = filename.replaceAll(emoji, " _" + EMOJI_NAMES[emoji] + "_ ")));
16871
+ EMOJIS.forEach(emoji => (filename = replaceAll(filename, emoji, " _" + EMOJI_NAMES[emoji] + "_ ")));
16871
16872
  }
16872
16873
  const replacementCharacter = options.filenameReplacementCharacter;
16873
16874
  filename = getValidFilename(filename, options.filenameReplacedCharacters, replacementCharacter);
@@ -16970,7 +16971,7 @@ async function evalTemplate(template = "", options, util, content, doc, dontRepl
16970
16971
  "lowercase": value => value.toLowerCase(),
16971
16972
  "uppercase": value => value.toUpperCase(),
16972
16973
  "capitalize": value => value.charAt(0).toUpperCase() + value.slice(1),
16973
- "replace": (value, searchValue, replaceValue) => searchValue && replaceValue ? value.replaceAll(searchValue, replaceValue) : value,
16974
+ "replace": (value, searchValue, replaceValue) => searchValue && replaceValue ? replaceAll(value, searchValue, replaceValue) : value,
16974
16975
  "trim": value => value.trim(),
16975
16976
  "trim-left": value => value.trimLeft(),
16976
16977
  "trim-right": value => value.trimRight(),
@@ -17012,10 +17013,10 @@ async function evalTemplate(template = "", options, util, content, doc, dontRepl
17012
17013
  return element && element.getAttribute(attribute);
17013
17014
  };
17014
17015
  }
17015
- template = template.replaceAll("\\%", "\\\\%");
17016
- template = template.replaceAll("\\{", "\\\\{");
17017
- template = template.replaceAll("\\|", "\\\\|");
17018
- template = template.replaceAll("\\>", "\\\\>");
17016
+ template = replaceAll(template, "\\%", "\\\\%");
17017
+ template = replaceAll(template, "\\{", "\\\\{");
17018
+ template = replaceAll(template, "\\|", "\\\\|");
17019
+ template = replaceAll(template, "\\>", "\\\\>");
17019
17020
  const result = (await parse(template, {
17020
17021
  async callFunction(name, [argument, optionalArguments], lengthData) {
17021
17022
  const fn = functions[name];
@@ -17047,10 +17048,10 @@ async function evalTemplate(template = "", options, util, content, doc, dontRepl
17047
17048
  }
17048
17049
  }));
17049
17050
  let resultString = result.join("");
17050
- resultString = resultString.replaceAll("\\\\%", "%");
17051
- resultString = resultString.replaceAll("\\\\{", "{");
17052
- resultString = resultString.replaceAll("\\\\|", "|");
17053
- resultString = resultString.replaceAll("\\\\>", ">");
17051
+ resultString = replaceAll(resultString, "\\\\%", "%");
17052
+ resultString = replaceAll(resultString, "\\\\{", "{");
17053
+ resultString = replaceAll(resultString, "\\\\|", "|");
17054
+ resultString = replaceAll(resultString, "\\\\>", ">");
17054
17055
  return resultString;
17055
17056
 
17056
17057
  function addDateVariables(date, prefix = "") {
@@ -17077,6 +17078,15 @@ async function evalTemplate(template = "", options, util, content, doc, dontRepl
17077
17078
  }
17078
17079
  }
17079
17080
 
17081
+ function replaceAll(string, search, replacement) {
17082
+ if (typeof string.replaceAll == "function") {
17083
+ return string.replaceAll(search, replacement);
17084
+ } else {
17085
+ const searchRegExp = new RegExp(search.replace(REGEXP_ESCAPE, "\\$1"), "g");
17086
+ return string.replace(searchRegExp, replacement);
17087
+ }
17088
+ }
17089
+
17080
17090
  async function getValue(valueGetter, dontReplaceSlash, replacementCharacter, lengthData) {
17081
17091
  const { maxLength, maxCharLength } = extractMaxLength(lengthData);
17082
17092
  let value = (await valueGetter()) || "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.2.25",
3
+ "version": "1.2.26",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -70,6 +70,8 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
70
70
  const REGEXP_MATCH_INDEX = /index\.html$/;
71
71
  const REGEXP_MATCH_FRAMES = /frames\//;
72
72
  const CHARSET_UTF8 = ";charset=utf-8";
73
+ const REGEXP_ESCAPE = /([{}()^$&.*?/+|[\\\\]|\]|-)/g;
74
+
73
75
  if (Array.isArray(content)) {
74
76
  content = new Blob([new Uint8Array(content)]);
75
77
  }
@@ -142,7 +144,7 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
142
144
  const position = textContent.indexOf(relativeFilename);
143
145
  if (position != -1) {
144
146
  parentResources.push(resourceFilename);
145
- textContent = textContent.replaceAll(relativeFilename, content);
147
+ textContent = replaceAll(textContent, relativeFilename, content);
146
148
  }
147
149
  }
148
150
  }
@@ -175,4 +177,13 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
175
177
  reader.onerror = reject;
176
178
  });
177
179
  }
180
+
181
+ function replaceAll(string, search, replacement) {
182
+ if (typeof string.replaceAll == "function") {
183
+ return string.replaceAll(search, replacement);
184
+ } else {
185
+ const searchRegExp = new RegExp(search.replace(REGEXP_ESCAPE, "\\$1"), "g");
186
+ return string.replace(searchRegExp, replacement);
187
+ }
188
+ }
178
189
  }