@yuneta/gobj-ui 7.26.7 → 7.26.8
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/dist/gobj-ui.cjs.js +372 -175
- package/dist/gobj-ui.es.js +372 -175
- package/package.json +1 -1
- package/src/c_g6_nodes_tree.js +28 -24
- package/src/c_yui_form.js +197 -63
- package/src/c_yui_gclass.js +22 -21
- package/src/c_yui_gobj_tree_js.js +7 -7
- package/src/c_yui_json.js +7 -6
- package/src/c_yui_json_graph.js +8 -7
- package/src/c_yui_json_pad.js +2 -1
- package/src/c_yui_map.js +25 -1
- package/src/c_yui_nav.js +7 -6
- package/src/c_yui_schema_editor.js +3 -2
- package/src/c_yui_shell.js +7 -0
- package/src/c_yui_treedb_topic_with_form.js +22 -17
- package/src/c_yui_treedb_topics.js +8 -7
- package/src/c_yui_window.js +72 -31
- package/src/c_yui_window_manager.js +3 -2
- package/src/form_json_field.js +10 -3
- package/src/form_json_field.test.js +6 -0
- package/src/form_json_field.wiring.test.js +1 -1
- package/src/form_table_rearm.wiring.test.js +158 -0
- package/src/g6_event_kw.js +36 -0
- package/src/nav_cards_helpers.js +2 -1
- package/src/nav_cards_helpers.test.js +7 -3
- package/src/schema_to_c.js +10 -0
- package/src/schema_to_c.test.js +8 -1
- package/src/shell_modals.js +5 -3
- package/src/shell_route_map.js +12 -13
- package/src/treedb_topics_transport.wiring.test.js +26 -0
- package/src/vite_plugin_yuneta_html.test.js +79 -0
- package/src/window_show.wiring.test.js +83 -0
- package/src/window_veto_back.wiring.test.js +35 -0
- package/src/yui_dev.js +13 -11
- package/src/yui_frontend_view.js +4 -4
- package/src/yui_gclass_view.js +3 -3
- package/src/yui_text.js +31 -0
- package/src/yui_text.test.js +39 -0
- package/vite-plugin-yuneta-html.js +9 -4
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* vite_plugin_yuneta_html.test.js
|
|
3
|
+
*
|
|
4
|
+
* The html transform of vite-plugin-yuneta-html.js: the policy is
|
|
5
|
+
* ALWAYS emitted (connect-src 'self' alone without csp_connect_src,
|
|
6
|
+
* and without a config.json at all), and the text of config.json is
|
|
7
|
+
* escaped where it lands in markup.
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2026, ArtGins.
|
|
10
|
+
* All Rights Reserved.
|
|
11
|
+
***********************************************************************/
|
|
12
|
+
import {describe, test, expect, vi} from "vitest";
|
|
13
|
+
import fs from "fs";
|
|
14
|
+
import os from "os";
|
|
15
|
+
import path from "path";
|
|
16
|
+
import {yunetaHtmlPlugin} from "../vite-plugin-yuneta-html.js";
|
|
17
|
+
|
|
18
|
+
const HTML = "<head><title></title>\n<!-- METADATA_PLACEHOLDER -->\n<!-- CSP_PLACEHOLDER --></head>";
|
|
19
|
+
|
|
20
|
+
function transform(config)
|
|
21
|
+
{
|
|
22
|
+
let configPath = path.join(os.tmpdir(), `yuneta-html-${process.pid}-${Math.random()}.json`);
|
|
23
|
+
if(config !== undefined) {
|
|
24
|
+
fs.writeFileSync(configPath, JSON.stringify(config));
|
|
25
|
+
}
|
|
26
|
+
const plugin = yunetaHtmlPlugin({defaultTitle: "Fallback", configPath});
|
|
27
|
+
try {
|
|
28
|
+
return plugin.transformIndexHtml.handler(HTML);
|
|
29
|
+
} finally {
|
|
30
|
+
if(config !== undefined) {
|
|
31
|
+
fs.unlinkSync(configPath);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function connect_src(html)
|
|
37
|
+
{
|
|
38
|
+
let m = html.match(/connect-src ([^;]*);/);
|
|
39
|
+
return m? m[1].split(/\s+/).filter(Boolean) : null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe("vite-plugin-yuneta-html", () => {
|
|
43
|
+
test("a declared csp_connect_src goes into connect-src, comments left out", () => {
|
|
44
|
+
const html = transform({
|
|
45
|
+
title: "App",
|
|
46
|
+
csp_connect_src: ["wss://host:1620", "_comment: why", "https://tiles.example"]
|
|
47
|
+
});
|
|
48
|
+
expect(connect_src(html)).toEqual(["'self'", "wss://host:1620", "https://tiles.example"]);
|
|
49
|
+
expect(html).toContain("<title>App</title>");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("no csp_connect_src: the policy is still there, connect-src 'self' only", () => {
|
|
53
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
54
|
+
const html = transform({title: "App"});
|
|
55
|
+
expect(connect_src(html)).toEqual(["'self'"]);
|
|
56
|
+
expect(warn).toHaveBeenCalled();
|
|
57
|
+
warn.mockRestore();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("no config.json: the policy is still there, with the fallback title", () => {
|
|
61
|
+
const err = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
62
|
+
const html = transform(undefined);
|
|
63
|
+
expect(connect_src(html)).toEqual(["'self'"]);
|
|
64
|
+
expect(html).toContain("<title>Fallback</title>");
|
|
65
|
+
err.mockRestore();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("what config.json says is escaped where it lands in markup", () => {
|
|
69
|
+
const html = transform({
|
|
70
|
+
title: "</title><script>x()</script>",
|
|
71
|
+
metadata: {description: '"><b>'},
|
|
72
|
+
csp_connect_src: ['wss://a" onload="x']
|
|
73
|
+
});
|
|
74
|
+
expect(html).not.toContain("<script>");
|
|
75
|
+
expect(html).toContain("</title><script>");
|
|
76
|
+
expect(html).not.toContain('content=""><b>"');
|
|
77
|
+
expect(html).not.toContain('wss://a" onload');
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* window_show.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* EV_SHOW brings a C_YUI_WINDOW back in front of the reader. Its
|
|
5
|
+
* action was an empty stub, so the map's second click on the same
|
|
6
|
+
* marker -- which finds the marker's window by name and sends it
|
|
7
|
+
* EV_SHOW instead of opening a second one -- did nothing for a
|
|
8
|
+
* window that was minimized or covered.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2026, ArtGins.
|
|
11
|
+
* All Rights Reserved.
|
|
12
|
+
***********************************************************************/
|
|
13
|
+
import {describe, test, expect, beforeAll} from "vitest";
|
|
14
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
15
|
+
|
|
16
|
+
install_dom_double();
|
|
17
|
+
|
|
18
|
+
if(typeof globalThis.matchMedia === "undefined") {
|
|
19
|
+
globalThis.matchMedia = () => ({matches: false, addEventListener() {}, removeEventListener() {}});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
SDATA_END, gclass_create,
|
|
24
|
+
gobj_start_up, gobj_create_yuno, gobj_create, gobj_create_service,
|
|
25
|
+
gobj_start, gobj_read_attr, gobj_send_event,
|
|
26
|
+
set_log_callback,
|
|
27
|
+
} = await import("@yuneta/gobj-js");
|
|
28
|
+
const {register_c_yui_window} = await import("./c_yui_window.js");
|
|
29
|
+
const {register_c_yui_window_manager} = await import("./c_yui_window_manager.js");
|
|
30
|
+
|
|
31
|
+
const logged = [];
|
|
32
|
+
let yuno = null;
|
|
33
|
+
|
|
34
|
+
beforeAll(async () => {
|
|
35
|
+
const i18next = (await import("i18next")).default;
|
|
36
|
+
await i18next.init({lng: "en", resources: {}});
|
|
37
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
38
|
+
set_log_callback((level, msg) => {
|
|
39
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
40
|
+
});
|
|
41
|
+
gclass_create("C_TEST_SHOW_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
42
|
+
register_c_yui_window();
|
|
43
|
+
register_c_yui_window_manager();
|
|
44
|
+
yuno = gobj_create_yuno("show_yuno", "C_TEST_SHOW_HOST", {});
|
|
45
|
+
gobj_start(yuno);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
function errors()
|
|
49
|
+
{
|
|
50
|
+
return logged.filter((l) => l.level === "error").map((l) => l.msg);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe("EV_SHOW", () => {
|
|
54
|
+
test("without a dock: a hidden window is shown, and goes on top of its layer", () => {
|
|
55
|
+
const a = gobj_create_service("show_a", "C_YUI_WINDOW", {header: "a", body: ["div", {}, "a"]}, yuno);
|
|
56
|
+
gobj_start(a);
|
|
57
|
+
const b = gobj_create_service("show_b", "C_YUI_WINDOW", {header: "b", body: ["div", {}, "b"]}, yuno);
|
|
58
|
+
gobj_start(b);
|
|
59
|
+
const $a = gobj_read_attr(a, "$container");
|
|
60
|
+
$a.style.setProperty("display", "none", "important");
|
|
61
|
+
|
|
62
|
+
gobj_send_event(a, "EV_SHOW", {}, yuno);
|
|
63
|
+
expect($a.style.getPropertyValue("display")).toBe("");
|
|
64
|
+
expect($a.parentNode.lastChild).toBe($a);
|
|
65
|
+
expect(errors()).toEqual([]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("with a dock: a minimized window comes back out of it", () => {
|
|
69
|
+
const dock = gobj_create_service("show_dock", "C_YUI_WINDOW_MANAGER", {}, yuno);
|
|
70
|
+
gobj_start(dock);
|
|
71
|
+
const w = gobj_create_service("show_w", "C_YUI_WINDOW",
|
|
72
|
+
{header: "w", body: ["div", {}, "w"], manager: dock}, yuno);
|
|
73
|
+
gobj_start(w);
|
|
74
|
+
const $w = gobj_read_attr(w, "$container");
|
|
75
|
+
|
|
76
|
+
gobj_send_event(dock, "EV_MINIMIZE_WINDOW", {window: w}, w);
|
|
77
|
+
expect($w.style.getPropertyValue("display")).toBe("none");
|
|
78
|
+
|
|
79
|
+
gobj_send_event(w, "EV_SHOW", {}, yuno);
|
|
80
|
+
expect($w.style.getPropertyValue("display")).toBe("");
|
|
81
|
+
expect(errors()).toEqual([]);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -27,6 +27,7 @@ const {register_c_yui_window} = await import("./c_yui_window.js");
|
|
|
27
27
|
|
|
28
28
|
const logged = [];
|
|
29
29
|
let veto = true;
|
|
30
|
+
let warning = null;
|
|
30
31
|
let yuno = null;
|
|
31
32
|
|
|
32
33
|
beforeAll(async () => {
|
|
@@ -43,6 +44,9 @@ beforeAll(async () => {
|
|
|
43
44
|
[["ST_IDLE", [
|
|
44
45
|
["EV_WINDOW_TO_CLOSE", (gobj, event, kw) => {
|
|
45
46
|
kw.abort_close = veto;
|
|
47
|
+
if(warning) {
|
|
48
|
+
kw.warning = warning;
|
|
49
|
+
}
|
|
46
50
|
return 0;
|
|
47
51
|
}, null]
|
|
48
52
|
]]],
|
|
@@ -57,6 +61,7 @@ beforeAll(async () => {
|
|
|
57
61
|
beforeEach(() => {
|
|
58
62
|
logged.length = 0;
|
|
59
63
|
veto = true;
|
|
64
|
+
warning = null;
|
|
60
65
|
});
|
|
61
66
|
|
|
62
67
|
function errors()
|
|
@@ -98,4 +103,34 @@ describe("a floating window that vetoes its close", () => {
|
|
|
98
103
|
expect(shell.priv.overlay_stack).toEqual([]);
|
|
99
104
|
expect(errors()).toEqual([]);
|
|
100
105
|
});
|
|
106
|
+
|
|
107
|
+
test("that ASKS first: Back closes the question, it does not stack another", async () => {
|
|
108
|
+
const app = gobj_create("vapp2", "C_TEST_VETO_APP", {}, yuno);
|
|
109
|
+
gobj_start(app);
|
|
110
|
+
const shell = gobj_create("vshell2", "C_YUI_SHELL",
|
|
111
|
+
{config: {shell: {}}, default_route: "/home", subscriber: app}, app);
|
|
112
|
+
gobj_start(shell);
|
|
113
|
+
logged.length = 0;
|
|
114
|
+
|
|
115
|
+
const win = gobj_create_service("vwin2", "C_YUI_WINDOW",
|
|
116
|
+
{subscriber: app, header: "x", body: ["div", {}, "body"]}, app);
|
|
117
|
+
gobj_start(win);
|
|
118
|
+
warning = "unsaved changes";
|
|
119
|
+
|
|
120
|
+
/* Back: the window asks. Only the question is on the stack. */
|
|
121
|
+
press_back();
|
|
122
|
+
expect(gobj_is_destroying(win)).toBe(false);
|
|
123
|
+
expect(shell.priv.overlay_stack.length).toBe(1);
|
|
124
|
+
expect(gobj_read_attr(win, "back_overlay")).toBe(null);
|
|
125
|
+
|
|
126
|
+
/* Back again: the question goes; the window takes its entry back
|
|
127
|
+
* only then, once there is nothing above it. */
|
|
128
|
+
press_back();
|
|
129
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
130
|
+
expect(gobj_is_destroying(win)).toBe(false);
|
|
131
|
+
const entry = gobj_read_attr(win, "back_overlay");
|
|
132
|
+
expect(entry).toBeTruthy();
|
|
133
|
+
expect(shell.priv.overlay_stack).toEqual([entry]);
|
|
134
|
+
expect(errors()).toEqual([]);
|
|
135
|
+
});
|
|
101
136
|
});
|
package/src/yui_dev.js
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
} from "@yuneta/gobj-js";
|
|
30
30
|
|
|
31
31
|
import i18next, {t} from 'i18next';
|
|
32
|
+
import {text_node} from "./yui_text.js";
|
|
32
33
|
|
|
33
34
|
/***********************************************************************
|
|
34
35
|
* Traffic model (bounded ring buffer)
|
|
@@ -628,7 +629,7 @@ function traffic_scalar_row(key, value)
|
|
|
628
629
|
value is one click away in the Expanded view. On a value SHORTER than
|
|
629
630
|
the clip -- almost all of them -- it repeated the visible text anyway. */
|
|
630
631
|
let val_children = [
|
|
631
|
-
['span', {class: 'TRAFFIC_VAL ' + cls}, text],
|
|
632
|
+
['span', {class: 'TRAFFIC_VAL ' + cls}, text_node(text)],
|
|
632
633
|
];
|
|
633
634
|
if((key in TRAFFIC_TS_FIELDS) && typeof value === "number") {
|
|
634
635
|
let iso = traffic_iso(value);
|
|
@@ -751,12 +752,12 @@ function traffic_value_node(key, value)
|
|
|
751
752
|
let hint = is_arr ?
|
|
752
753
|
[['span', {class: 'TRAFFIC_NEST_HINT'}, `[${count}]`]] :
|
|
753
754
|
object_preview_parts(value, count).map(
|
|
754
|
-
(t) => ['span', {class: 'TRAFFIC_PREV ' + t.cls}, t.text]
|
|
755
|
+
(t) => ['span', {class: 'TRAFFIC_PREV ' + t.cls}, text_node(t.text)]
|
|
755
756
|
);
|
|
756
757
|
return ['details', {class: 'TRAFFIC_NEST'}, [
|
|
757
758
|
['summary', {}, [
|
|
758
759
|
['span', {class: 'TRAFFIC_BULLET'}, '▸'],
|
|
759
|
-
['span', {class: 'TRAFFIC_NEST_KEY'}, key],
|
|
760
|
+
['span', {class: 'TRAFFIC_NEST_KEY'}, text_node(key)],
|
|
760
761
|
['span', {class: 'TRAFFIC_NEST_HINT_WRAP'}, hint],
|
|
761
762
|
]],
|
|
762
763
|
['div', {class: 'TRAFFIC_KW'}, traffic_bullets(value)],
|
|
@@ -804,12 +805,12 @@ function traffic_bullets(obj)
|
|
|
804
805
|
function event_spans(e)
|
|
805
806
|
{
|
|
806
807
|
let spans = [['span', {class: 'TRAFFIC_ARROW'}, dir_arrow(e.dir)],
|
|
807
|
-
['span', {class: 'TRAFFIC_EVENT'}, e.event]];
|
|
808
|
+
['span', {class: 'TRAFFIC_EVENT'}, text_node(e.event)]];
|
|
808
809
|
if(e.command) {
|
|
809
|
-
spans.push(['span', {class: 'TRAFFIC_CMD'}, e.command]);
|
|
810
|
+
spans.push(['span', {class: 'TRAFFIC_CMD'}, text_node(e.command)]);
|
|
810
811
|
}
|
|
811
812
|
if(e.title) {
|
|
812
|
-
spans.push(['span', {class: 'TRAFFIC_SRC'}, e.title]);
|
|
813
|
+
spans.push(['span', {class: 'TRAFFIC_SRC'}, text_node(e.title)]);
|
|
813
814
|
}
|
|
814
815
|
return spans;
|
|
815
816
|
}
|
|
@@ -891,7 +892,7 @@ function render_full(e)
|
|
|
891
892
|
}
|
|
892
893
|
let children = [
|
|
893
894
|
['div', {class: 'TRAFFIC_HEADER'}, head],
|
|
894
|
-
['pre', {class: 'TRAFFIC_FULL'}, text],
|
|
895
|
+
['pre', {class: 'TRAFFIC_FULL'}, document.createTextNode(String(text))],
|
|
895
896
|
];
|
|
896
897
|
return createElement2(['div', {class: 'TRAFFIC_ENTRY ' + dir_class(e.dir)}, children]);
|
|
897
898
|
}
|
|
@@ -1860,10 +1861,11 @@ function setup_dev(self, show)
|
|
|
1860
1861
|
center: false,
|
|
1861
1862
|
title: "developer",
|
|
1862
1863
|
icon: "yi-terminal",
|
|
1863
|
-
/* Opt into the dock/taskbar if the app provides one
|
|
1864
|
-
*
|
|
1865
|
-
*
|
|
1866
|
-
*
|
|
1864
|
+
/* Opt into the dock/taskbar if the app provides one; null =
|
|
1865
|
+
* no dock. (gobj_find_service() answers null for an absent
|
|
1866
|
+
* service since gobj-js 7.12.0; the `|| null` is from when it
|
|
1867
|
+
* answered undefined, which logged "attr undefined: manager",
|
|
1868
|
+
* and stays as a guard.) */
|
|
1867
1869
|
manager: gobj_find_service("__window_manager__", false) || null,
|
|
1868
1870
|
/* A monitor is watched WHILE navigating: closing it on every
|
|
1869
1871
|
* route change made it useless for the one job it has. A
|
package/src/yui_frontend_view.js
CHANGED
|
@@ -74,10 +74,10 @@ function setup_frontend_view(self)
|
|
|
74
74
|
title: "frontend view",
|
|
75
75
|
icon: "yi-hexagon-nodes",
|
|
76
76
|
body: $body,
|
|
77
|
-
/* Opt into the dock/taskbar if the app provides one
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
77
|
+
/* Opt into the dock/taskbar if the app provides one; null = no
|
|
78
|
+
* dock. (gobj_find_service() answers null for an absent service
|
|
79
|
+
* since gobj-js 7.12.0; the `|| null` is from when it answered
|
|
80
|
+
* undefined, and stays as a guard.) */
|
|
81
81
|
manager: gobj_find_service("__window_manager__", false) || null,
|
|
82
82
|
},
|
|
83
83
|
self
|
package/src/yui_gclass_view.js
CHANGED
|
@@ -228,9 +228,9 @@ function open_gclass_view(host, gclass_name, opts)
|
|
|
228
228
|
body: $box,
|
|
229
229
|
/* The same dock the other windows are on: raising a window
|
|
230
230
|
* is the manager's job, and a viewer registered nowhere
|
|
231
|
-
* cannot come to the front when the reader clicks it.
|
|
232
|
-
* null
|
|
233
|
-
*
|
|
231
|
+
* cannot come to the front when the reader clicks it. An
|
|
232
|
+
* absent service is null (gobj-js 7.12.0+); the `|| null` is
|
|
233
|
+
* the guard from when it was undefined. */
|
|
234
234
|
manager: gobj_find_service("__window_manager__", false) || null,
|
|
235
235
|
on_close: on_close,
|
|
236
236
|
},
|
package/src/yui_text.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* yui_text.js
|
|
3
|
+
*
|
|
4
|
+
* DATA as text for createElement2().
|
|
5
|
+
*
|
|
6
|
+
* createElement2() takes a string content that starts with '<' for
|
|
7
|
+
* MARKUP and parses it (that is how a component passes an inline
|
|
8
|
+
* icon). So a value that came from outside -- a backend answer, a
|
|
9
|
+
* treedb node, a name somebody typed, a frame of the traffic -- must
|
|
10
|
+
* never go in as a bare string: "<img src=x onerror=...>" would run.
|
|
11
|
+
* It goes in as a Text node, which is always text.
|
|
12
|
+
*
|
|
13
|
+
* Trimmed like createElement2() trims a string, so the change of
|
|
14
|
+
* form does not change what is shown. A Text node under an
|
|
15
|
+
* `i18n`/`data-i18n` element is still re-translated by
|
|
16
|
+
* refresh_language(), which sets textContent.
|
|
17
|
+
*
|
|
18
|
+
* Copyright (c) 2026, ArtGins.
|
|
19
|
+
* All Rights Reserved.
|
|
20
|
+
***********************************************************************/
|
|
21
|
+
|
|
22
|
+
/************************************************************
|
|
23
|
+
* A Text node with `value` as its text ("" for null/undefined).
|
|
24
|
+
************************************************************/
|
|
25
|
+
export function text_node(value)
|
|
26
|
+
{
|
|
27
|
+
if(value === null || value === undefined) {
|
|
28
|
+
return document.createTextNode("");
|
|
29
|
+
}
|
|
30
|
+
return document.createTextNode(String(value).trim());
|
|
31
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* yui_text.test.js
|
|
3
|
+
*
|
|
4
|
+
* Data goes into createElement2() as a Text node: a string that
|
|
5
|
+
* starts with '<' is parsed as markup there.
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2026, ArtGins.
|
|
8
|
+
* All Rights Reserved.
|
|
9
|
+
***********************************************************************/
|
|
10
|
+
import {describe, test, expect} from "vitest";
|
|
11
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
12
|
+
|
|
13
|
+
install_dom_double();
|
|
14
|
+
|
|
15
|
+
const {createElement2} = await import("@yuneta/gobj-js");
|
|
16
|
+
const {text_node} = await import("./yui_text.js");
|
|
17
|
+
const {card_descriptor} = await import("./nav_cards_helpers.js");
|
|
18
|
+
|
|
19
|
+
const EVIL = "<img src=x onerror=alert(1)>";
|
|
20
|
+
|
|
21
|
+
describe("text_node()", () => {
|
|
22
|
+
test("a value that looks like markup stays text", () => {
|
|
23
|
+
const $el = createElement2(["span", {}, text_node(EVIL)]);
|
|
24
|
+
expect($el.querySelector("img")).toBe(null);
|
|
25
|
+
expect($el.textContent).toBe(EVIL);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("trimmed like a string content, and null is empty", () => {
|
|
29
|
+
expect(text_node(" a ").textContent).toBe("a");
|
|
30
|
+
expect(text_node(null).textContent).toBe("");
|
|
31
|
+
expect(text_node(0).textContent).toBe("0");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("a nav card named by a backend (set_submenu) shows its name as text", () => {
|
|
35
|
+
const $card = createElement2(card_descriptor({id: "x", name: EVIL, route: "/x"}, true));
|
|
36
|
+
expect($card.querySelector("img")).toBe(null);
|
|
37
|
+
expect($card.textContent).toContain(EVIL);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -44,13 +44,15 @@ export function yunetaHtmlPlugin(options = {}) {
|
|
|
44
44
|
const configPath = options.configPath ||
|
|
45
45
|
path.resolve(process.cwd(), "config.json");
|
|
46
46
|
|
|
47
|
+
/* Without a config.json the page still gets its policy
|
|
48
|
+
* (connect-src 'self' only): it used to get none at all. */
|
|
49
|
+
let config = {};
|
|
47
50
|
if (!fs.existsSync(configPath)) {
|
|
48
51
|
console.error("⚠️ config.json not found at", configPath);
|
|
49
|
-
|
|
52
|
+
} else {
|
|
53
|
+
config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
50
54
|
}
|
|
51
55
|
|
|
52
|
-
const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
53
|
-
|
|
54
56
|
/*------------------------------------------*
|
|
55
57
|
* Title
|
|
56
58
|
*------------------------------------------*/
|
|
@@ -101,8 +103,11 @@ export function yunetaHtmlPlugin(options = {}) {
|
|
|
101
103
|
{
|
|
102
104
|
let origins = [];
|
|
103
105
|
if (Array.isArray(config.csp_connect_src)) {
|
|
106
|
+
/* Escaped: an origin lands inside the content="..."
|
|
107
|
+
* attribute, where a quote would end it. */
|
|
104
108
|
origins = config.csp_connect_src
|
|
105
|
-
.filter(s => !s.startsWith("_comment"))
|
|
109
|
+
.filter(s => typeof s === "string" && !s.startsWith("_comment"))
|
|
110
|
+
.map(escape_html);
|
|
106
111
|
} else {
|
|
107
112
|
console.warn(
|
|
108
113
|
"⚠️ config.json has no csp_connect_src array: " +
|