marko 5.38.34 → 5.38.36

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,17 @@
1
+ "use strict";
2
+ const unsafeCharsReg = />/g;
3
+ const replaceMatch = () => ">";
4
+ const escape = (str) =>
5
+ unsafeCharsReg.test(str) ? str.replace(unsafeCharsReg, replaceMatch) : str;
6
+
7
+ /**
8
+ * Escapes content placed inside an <html-comment> tag.
9
+ *
10
+ * For example:
11
+ * <html-comment>${userInput}</html-comment>
12
+ *
13
+ * Without escaping, a value of `><script>alert(1)</script><!--` would close the comment early.
14
+ */
15
+ module.exports = function escapeCommentHelper(value) {
16
+ return escape(value + "");
17
+ };
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const unsafeCharsReg = /<\/script/g;
2
+ const unsafeCharsReg = /<\/script/gi;
3
3
  const replaceMatch = () => "\\x3C/script";
4
4
  const escape = (str) =>
5
5
  unsafeCharsReg.test(str) ? str.replace(unsafeCharsReg, replaceMatch) : str;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const unsafeCharsReg = /<\/style/g;
2
+ const unsafeCharsReg = /<\/style/gi;
3
3
  const replaceMatch = () => "\\3C/style";
4
4
  const escape = (str) =>
5
5
  unsafeCharsReg.test(str) ? str.replace(unsafeCharsReg, replaceMatch) : str;
@@ -5,6 +5,7 @@ var _babelUtils = require("@marko/compiler/babel-utils");
5
5
 
6
6
 
7
7
 
8
+
8
9
  var _htmlOutWrite = _interopRequireDefault(require("../../util/html-out-write"));
9
10
  var _vdomOutWrite = _interopRequireDefault(require("../../util/vdom-out-write"));
10
11
  var _withPreviousLocation = _interopRequireDefault(require("../../util/with-previous-location"));function _interopRequireDefault(e) {return e && e.__esModule ? e : { default: e };}
@@ -15,11 +16,30 @@ function enter(path) {
15
16
  (0, _babelUtils.assertNoAttributes)(path);
16
17
 
17
18
  if (path.hub.file.markoOpts.output === "html") {
18
- path.replaceWithMultiple([
19
- (0, _htmlOutWrite.default)`<!--`,
20
- ...path.node.body.body,
21
- (0, _htmlOutWrite.default)`-->`]
22
- );
19
+ const { file } = path.hub;
20
+ const nodes = [(0, _htmlOutWrite.default)`<!--`];
21
+
22
+ for (const child of path.node.body.body) {
23
+ if (_compiler.types.isMarkoText(child)) {
24
+ nodes.push(child);
25
+ } else if (_compiler.types.isMarkoPlaceholder(child)) {
26
+ const escapeFnModule = child.escape ?
27
+ "marko/src/runtime/html/helpers/escape-comment-placeholder.js" :
28
+ "marko/src/runtime/helpers/to-string.js";
29
+ const escapeFnAlias = child.escape ?
30
+ "marko_escapeComment" :
31
+ "marko_to_string";
32
+ nodes.push(
33
+ (0, _htmlOutWrite.default)`${_compiler.types.callExpression(
34
+ (0, _babelUtils.importDefault)(file, escapeFnModule, escapeFnAlias),
35
+ [child.value]
36
+ )}`
37
+ );
38
+ }
39
+ }
40
+
41
+ nodes.push((0, _htmlOutWrite.default)`-->`);
42
+ path.replaceWithMultiple(nodes.filter(Boolean));
23
43
  } else {
24
44
  const templateQuasis = [];
25
45
  const templateExpressions = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "5.38.34",
3
+ "version": "5.38.36",
4
4
  "description": "UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.",
5
5
  "keywords": [
6
6
  "front-end",
@@ -70,7 +70,7 @@
70
70
  },
71
71
  "dependencies": {
72
72
  "@marko/compiler": "^5.39.62",
73
- "@marko/runtime-tags": "^6.0.160",
73
+ "@marko/runtime-tags": "^6.0.164",
74
74
  "app-module-path": "^2.2.0",
75
75
  "argly": "^1.2.0",
76
76
  "browser-refresh-client": "1.1.4",
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ const unsafeCharsReg = />/g;
3
+ const replaceMatch = () => "&gt;";
4
+ const escape = (str) =>
5
+ unsafeCharsReg.test(str) ? str.replace(unsafeCharsReg, replaceMatch) : str;
6
+
7
+ /**
8
+ * Escapes content placed inside an <html-comment> tag.
9
+ *
10
+ * For example:
11
+ * <html-comment>${userInput}</html-comment>
12
+ *
13
+ * Without escaping, a value of `><script>alert(1)</script><!--` would close the comment early.
14
+ */
15
+ module.exports = function escapeCommentHelper(value) {
16
+ return escape(value + "");
17
+ };
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const unsafeCharsReg = /<\/script/g;
2
+ const unsafeCharsReg = /<\/script/gi;
3
3
  const replaceMatch = () => "\\x3C/script";
4
4
  const escape = (str) =>
5
5
  unsafeCharsReg.test(str) ? str.replace(unsafeCharsReg, replaceMatch) : str;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const unsafeCharsReg = /<\/style/g;
2
+ const unsafeCharsReg = /<\/style/gi;
3
3
  const replaceMatch = () => "\\3C/style";
4
4
  const escape = (str) =>
5
5
  unsafeCharsReg.test(str) ? str.replace(unsafeCharsReg, replaceMatch) : str;
@@ -3,6 +3,7 @@ import {
3
3
  assertNoArgs,
4
4
  assertNoAttributes,
5
5
  assertNoParams,
6
+ importDefault,
6
7
  } from "@marko/compiler/babel-utils";
7
8
 
8
9
  import writeHTML from "../../util/html-out-write";
@@ -15,11 +16,30 @@ export function enter(path) {
15
16
  assertNoAttributes(path);
16
17
 
17
18
  if (path.hub.file.markoOpts.output === "html") {
18
- path.replaceWithMultiple([
19
- writeHTML`<!--`,
20
- ...path.node.body.body,
21
- writeHTML`-->`,
22
- ]);
19
+ const { file } = path.hub;
20
+ const nodes = [writeHTML`<!--`];
21
+
22
+ for (const child of path.node.body.body) {
23
+ if (t.isMarkoText(child)) {
24
+ nodes.push(child);
25
+ } else if (t.isMarkoPlaceholder(child)) {
26
+ const escapeFnModule = child.escape
27
+ ? "marko/src/runtime/html/helpers/escape-comment-placeholder.js"
28
+ : "marko/src/runtime/helpers/to-string.js";
29
+ const escapeFnAlias = child.escape
30
+ ? "marko_escapeComment"
31
+ : "marko_to_string";
32
+ nodes.push(
33
+ writeHTML`${t.callExpression(
34
+ importDefault(file, escapeFnModule, escapeFnAlias),
35
+ [child.value],
36
+ )}`,
37
+ );
38
+ }
39
+ }
40
+
41
+ nodes.push(writeHTML`-->`);
42
+ path.replaceWithMultiple(nodes.filter(Boolean));
23
43
  } else {
24
44
  const templateQuasis = [];
25
45
  const templateExpressions = [];