ghtml 2.0.3 → 2.0.4
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.
- package/.eslintrc.json +1 -0
- package/package.json +1 -1
- package/src/html.js +32 -20
- package/test/index.js +7 -0
package/.eslintrc.json
CHANGED
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Replace your template engine with fast JavaScript by leveraging the power of tagged templates.",
|
|
4
4
|
"author": "Gürgün Dayıoğlu",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "2.0.
|
|
6
|
+
"version": "2.0.4",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./src/index.js",
|
|
9
9
|
"exports": {
|
package/src/html.js
CHANGED
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
const arrayIsArray = Array.isArray;
|
|
2
|
-
|
|
3
2
|
const symbolIterator = Symbol.iterator;
|
|
4
|
-
|
|
5
3
|
const symbolAsyncIterator = Symbol.asyncIterator;
|
|
6
4
|
|
|
7
|
-
const
|
|
8
|
-
'"': """,
|
|
9
|
-
"&": "&",
|
|
10
|
-
"'": "'",
|
|
11
|
-
"<": "<",
|
|
12
|
-
">": ">",
|
|
13
|
-
"`": "`",
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const escapeRegExp = new RegExp(`[${Object.keys(escapeDictionary).join("")}]`);
|
|
17
|
-
|
|
5
|
+
const escapeRegExp = /["&'<>`]/;
|
|
18
6
|
const escapeFunction = (string) => {
|
|
19
7
|
const stringLength = string.length;
|
|
20
8
|
let start = 0;
|
|
@@ -22,15 +10,37 @@ const escapeFunction = (string) => {
|
|
|
22
10
|
let escaped = "";
|
|
23
11
|
|
|
24
12
|
do {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
13
|
+
switch (string.charCodeAt(end++)) {
|
|
14
|
+
case 34: // "
|
|
15
|
+
escaped += string.slice(start, end - 1) + """;
|
|
16
|
+
start = end;
|
|
17
|
+
continue;
|
|
18
|
+
case 38: // &
|
|
19
|
+
escaped += string.slice(start, end - 1) + "&";
|
|
20
|
+
start = end;
|
|
21
|
+
continue;
|
|
22
|
+
case 39: // '
|
|
23
|
+
escaped += string.slice(start, end - 1) + "'";
|
|
24
|
+
start = end;
|
|
25
|
+
continue;
|
|
26
|
+
case 60: // <
|
|
27
|
+
escaped += string.slice(start, end - 1) + "<";
|
|
28
|
+
start = end;
|
|
29
|
+
continue;
|
|
30
|
+
case 62: // >
|
|
31
|
+
escaped += string.slice(start, end - 1) + ">";
|
|
32
|
+
start = end;
|
|
33
|
+
continue;
|
|
34
|
+
case 96: // `
|
|
35
|
+
escaped += string.slice(start, end - 1) + "`";
|
|
36
|
+
start = end;
|
|
37
|
+
continue;
|
|
30
38
|
}
|
|
31
39
|
} while (end !== stringLength);
|
|
32
40
|
|
|
33
|
-
|
|
41
|
+
escaped += string.slice(start, end);
|
|
42
|
+
|
|
43
|
+
return escaped;
|
|
34
44
|
};
|
|
35
45
|
|
|
36
46
|
/**
|
|
@@ -64,7 +74,9 @@ const html = ({ raw: literals }, ...expressions) => {
|
|
|
64
74
|
accumulator += literal + string;
|
|
65
75
|
}
|
|
66
76
|
|
|
67
|
-
|
|
77
|
+
accumulator += literals[index];
|
|
78
|
+
|
|
79
|
+
return accumulator;
|
|
68
80
|
};
|
|
69
81
|
|
|
70
82
|
/**
|
package/test/index.js
CHANGED
|
@@ -63,6 +63,13 @@ test("renders unsafe content", () => {
|
|
|
63
63
|
);
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
+
test("renders unsafe content /2", () => {
|
|
67
|
+
assert.strictEqual(
|
|
68
|
+
html`<p>${`${descriptionUnsafe}"&\``}</p>`,
|
|
69
|
+
`<p><script>alert('This is an unsafe description.')</script>"&`</p>`,
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
|
|
66
73
|
test("renders arrays", () => {
|
|
67
74
|
assert.strictEqual(
|
|
68
75
|
html`<p>${[descriptionSafe, descriptionUnsafe]}</p>`,
|