single-file-core 1.6.2 → 1.6.3

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.
@@ -0,0 +1,62 @@
1
+ /*
2
+ * Copyright 2010-2022 Gildas Lormeau
3
+ * contact : gildas.lormeau <at> gmail.com
4
+ *
5
+ * This file is part of SingleFile.
6
+ *
7
+ * The code in this file is free software: you can redistribute it and/or
8
+ * modify it under the terms of the GNU Affero General Public License
9
+ * (GNU AGPL) as published by the Free Software Foundation, either version 3
10
+ * of the License, or (at your option) any later version.
11
+ *
12
+ * The code in this file is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
15
+ * General Public License for more details.
16
+ *
17
+ * As additional permission under GNU AGPL version 3 section 7, you may
18
+ * distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU
19
+ * AGPL normally required by section 4, provided you include this license
20
+ * notice and a URL through which recipients can access the Corresponding
21
+ * Source.
22
+ */
23
+
24
+ const DEFAULT_REPLACED_CHARACTERS = ["~", "+", "?", "%", "*", ":", "|", "\"", "<", ">", "\\\\", "\x00-\x1f", "\x7F"];
25
+ const DEFAULT_REPLACEMENT_CHARACTER = "_";
26
+ const DEFAULT_REPLACEMENT_CHARACTERS = ["~", "+", "?", "%", "*", ":", "|", """, "<", ">", "\"];
27
+ const CHARACTER_CLASS_SPECIAL_CHARACTERS = ["[", "]", "^", "-", "\\"];
28
+
29
+ export {
30
+ getValidFilename,
31
+ DEFAULT_REPLACED_CHARACTERS,
32
+ DEFAULT_REPLACEMENT_CHARACTER,
33
+ DEFAULT_REPLACEMENT_CHARACTERS
34
+ };
35
+
36
+ function getValidFilename(filename, replacedCharacters = DEFAULT_REPLACED_CHARACTERS, replacementCharacter = DEFAULT_REPLACEMENT_CHARACTER, replacementCharacters = DEFAULT_REPLACEMENT_CHARACTERS) {
37
+ replacementCharacters.forEach((indexReplacementCharacter, index) => {
38
+ if (indexReplacementCharacter && replacedCharacters[index] !== undefined && indexReplacementCharacter != replacedCharacters[index]) {
39
+ // no "+" here, unlike the fallback below: a lookalike replaces its character one for
40
+ // one, so collapsing a run would drop characters the name needs ("C++" -> "C+")
41
+ filename = filename.replace(new RegExp("[" + getCharacterClassContent(replacedCharacters[index]) + "]", "g"), indexReplacementCharacter);
42
+ }
43
+ });
44
+ replacedCharacters.forEach((replacedCharacter, index) => {
45
+ if (!replacementCharacters[index]) {
46
+ filename = filename.replace(new RegExp("[" + getCharacterClassContent(replacedCharacter) + "]+", "g"), replacementCharacter);
47
+ }
48
+ });
49
+ filename = filename
50
+ .replace(/\.\.\//g, "")
51
+ .replace(/^\/+/, "")
52
+ .replace(/\/+/g, "/")
53
+ .replace(/\/$/, "")
54
+ .replace(/\.$/, "")
55
+ .replace(/\.\//g, "." + replacementCharacter)
56
+ .replace(/\/\./g, "/" + replacementCharacter);
57
+ return filename;
58
+ }
59
+
60
+ function getCharacterClassContent(characters) {
61
+ return characters.length == 1 && CHARACTER_CLASS_SPECIAL_CHARACTERS.includes(characters) ? "\\" + characters : characters;
62
+ }
package/core/helper.js CHANGED
@@ -32,6 +32,12 @@ import {
32
32
  MESSAGE_PREFIX,
33
33
  NO_SCRIPT_PROPERTY_NAME
34
34
  } from "./constants.js";
35
+ import {
36
+ getValidFilename,
37
+ DEFAULT_REPLACED_CHARACTERS,
38
+ DEFAULT_REPLACEMENT_CHARACTER,
39
+ DEFAULT_REPLACEMENT_CHARACTERS
40
+ } from "./filename.js";
35
41
 
36
42
  const ON_BEFORE_CAPTURE_EVENT_NAME = SINGLE_FILE_PREFIX + "on-before-capture";
37
43
  const ON_AFTER_CAPTURE_EVENT_NAME = SINGLE_FILE_PREFIX + "on-after-capture";
@@ -77,10 +83,6 @@ const INFOBAR_TAGNAME = infobar.INFOBAR_TAGNAME;
77
83
  const EMPTY_RESOURCE = "data:,";
78
84
  const POSTER_CONTENT_TYPES = ["image/webp", "image/jpeg"];
79
85
  const POSTER_QUALITY = 0.8;
80
- const DEFAULT_REPLACED_CHARACTERS = ["~", "+", "?", "%", "*", ":", "|", "\"", "<", ">", "\\\\", "\x00-\x1f", "\x7F"];
81
- const DEFAULT_REPLACEMENT_CHARACTER = "_";
82
- const DEFAULT_REPLACEMENT_CHARACTERS = ["~", "+", "?", "%", "*", ":", "|", """, "<", ">", "\"];
83
- const CHARACTER_CLASS_SPECIAL_CHARACTERS = ["[", "]", "^", "-", "\\"];
84
86
  const NESTING_TRACK_ID_ATTRIBUTE_NAME = "data-sf-nesting-track-id";
85
87
  const DEPRECATED_OPTION_NAMES = {
86
88
  loadDeferredImages: "loadDeferredContent",
@@ -927,34 +929,6 @@ function getComputedStyle(win, element, pseudoElement) {
927
929
  }
928
930
  }
929
931
 
930
- function getValidFilename(filename, replacedCharacters = DEFAULT_REPLACED_CHARACTERS, replacementCharacter = DEFAULT_REPLACEMENT_CHARACTER, replacementCharacters = DEFAULT_REPLACEMENT_CHARACTERS) {
931
- replacementCharacters.forEach((indexReplacementCharacter, index) => {
932
- if (indexReplacementCharacter && replacedCharacters[index] !== undefined && indexReplacementCharacter != replacedCharacters[index]) {
933
- // no "+" here, unlike the fallback below: a lookalike replaces its character one for
934
- // one, so collapsing a run would drop characters the name needs ("C++" -> "C+")
935
- filename = filename.replace(new RegExp("[" + getCharacterClassContent(replacedCharacters[index]) + "]", "g"), indexReplacementCharacter);
936
- }
937
- });
938
- replacedCharacters.forEach((replacedCharacter, index) => {
939
- if (!replacementCharacters[index]) {
940
- filename = filename.replace(new RegExp("[" + getCharacterClassContent(replacedCharacter) + "]+", "g"), replacementCharacter);
941
- }
942
- });
943
- filename = filename
944
- .replace(/\.\.\//g, "")
945
- .replace(/^\/+/, "")
946
- .replace(/\/+/g, "/")
947
- .replace(/\/$/, "")
948
- .replace(/\.$/, "")
949
- .replace(/\.\//g, "." + replacementCharacter)
950
- .replace(/\/\./g, "/" + replacementCharacter);
951
- return filename;
952
- }
953
-
954
- function getCharacterClassContent(characters) {
955
- return characters.length == 1 && CHARACTER_CLASS_SPECIAL_CHARACTERS.includes(characters) ? "\\" + characters : characters;
956
- }
957
-
958
932
  function parseDocContent(content, baseURI) {
959
933
  const doc = (new DOMParser()).parseFromString(content, "text/html");
960
934
  if (!doc.head) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Copyright 2010-2022 Gildas Lormeau
3
+ * contact : gildas.lormeau <at> gmail.com
4
+ *
5
+ * This file is part of SingleFile.
6
+ *
7
+ * The code in this file is free software: you can redistribute it and/or
8
+ * modify it under the terms of the GNU Affero General Public License
9
+ * (GNU AGPL) as published by the Free Software Foundation, either version 3
10
+ * of the License, or (at your option) any later version.
11
+ *
12
+ * The code in this file is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
15
+ * General Public License for more details.
16
+ *
17
+ * As additional permission under GNU AGPL version 3 section 7, you may
18
+ * distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU
19
+ * AGPL normally required by section 4, provided you include this license
20
+ * notice and a URL through which recipients can access the Corresponding
21
+ * Source.
22
+ */
23
+
24
+ const DEFAULT_MAX_APPENDED_DATA_LENGTH = 16361;
25
+
26
+ export {
27
+ DEFAULT_MAX_APPENDED_DATA_LENGTH
28
+ };
@@ -39,6 +39,9 @@ import {
39
39
  import {
40
40
  router
41
41
  } from "./compression-router.js";
42
+ import {
43
+ DEFAULT_MAX_APPENDED_DATA_LENGTH
44
+ } from "./compression-constants.js";
42
45
 
43
46
  const { Blob, fetch, TextEncoder, DOMParser } = globalThis;
44
47
 
@@ -89,7 +92,6 @@ const PNG_SIGNATURE_LENGTH = 8;
89
92
  const PNG_IHDR_LENGTH = 25;
90
93
  const COMMENT_LENGTH_FIELD_LENGTH = 2;
91
94
  const MAX_ZIP_COMMENT_LENGTH = 65535;
92
- const DEFAULT_MAX_APPENDED_DATA_LENGTH = 16361;
93
95
  const PDF_ENTRY_FILENAME = "page.pdf";
94
96
  const PRESCAN_WINDOW_LENGTH = 1024;
95
97
  const PNG_TEXT_CHUNK_HEADER_LENGTH = 12;