@zoijs/core 1.3.2 → 1.5.0
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/CHANGELOG.md +132 -103
- package/README.md +173 -154
- package/package.json +71 -63
- package/src/core/each.js +24 -24
- package/src/core/html.js +24 -5
- package/src/core/renderer.js +472 -470
- package/src/devtools.d.ts +56 -0
- package/src/index.d.ts +185 -185
- package/src/reactivity/core.js +7 -0
- package/src/reactivity/devtools.js +77 -0
- package/src/server.d.ts +53 -0
- package/src/server.js +42 -0
- package/src/utils/security.js +21 -0
package/src/utils/security.js
CHANGED
|
@@ -14,6 +14,27 @@ export function toText(value) {
|
|
|
14
14
|
return value === null || value === undefined ? "" : String(value);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
// HTML-escaping for SERVER string rendering (@zoijs/ssr). The client renderer
|
|
18
|
+
// never needs these — it writes text via Text nodes and values via setAttribute,
|
|
19
|
+
// both of which are inert/escaped by the platform. On a server there is no DOM, so
|
|
20
|
+
// the same safety must be applied by escaping into the HTML string. Kept here so
|
|
21
|
+
// escaping lives in one place alongside the other security predicates.
|
|
22
|
+
|
|
23
|
+
/** Escape a value for insertion as HTML TEXT content. */
|
|
24
|
+
export function escapeText(value) {
|
|
25
|
+
return toText(value).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Escape a value for insertion inside a double-quoted attribute value. */
|
|
29
|
+
export function escapeAttr(value) {
|
|
30
|
+
return toText(value).replace(/&/g, "&").replace(/"/g, """);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Attribute names that carry a URL — their values are scheme-checked (isSafeUrl).
|
|
34
|
+
// Shared by the client renderer (DOM) and @zoijs/ssr (string) so both make the
|
|
35
|
+
// exact same safety decision.
|
|
36
|
+
export const URL_ATTRS = new Set(["href", "src", "action", "formaction", "poster", "ping", "xlink:href"]);
|
|
37
|
+
|
|
17
38
|
// Allowlisted URL schemes for URL-bearing attributes (href, src, ...).
|
|
18
39
|
const SAFE_SCHEMES = new Set(["http", "https", "mailto", "tel"]);
|
|
19
40
|
// data: is allowed only for raster image MIME types (never text/html, never SVG,
|