@yuneta/gobj-ui 7.26.8 → 7.26.10

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.
@@ -65,15 +65,30 @@ describe("vite-plugin-yuneta-html", () => {
65
65
  err.mockRestore();
66
66
  });
67
67
 
68
+ test("an entry that is not a single source is refused, the rest kept", () => {
69
+ const err = vi.spyOn(console, "error").mockImplementation(() => {});
70
+ const html = transform({
71
+ title: "App",
72
+ csp_connect_src: [
73
+ "wss://a:1; base-uri *", "wss://b, wss://c", "wss://d wss://e",
74
+ "wss://ok:1620"
75
+ ]
76
+ });
77
+ expect(connect_src(html)).toEqual(["'self'", "wss://ok:1620"]);
78
+ expect(html).not.toContain("base-uri");
79
+ expect(err).toHaveBeenCalledTimes(3);
80
+ err.mockRestore();
81
+ });
82
+
68
83
  test("what config.json says is escaped where it lands in markup", () => {
69
84
  const html = transform({
70
85
  title: "</title><script>x()</script>",
71
86
  metadata: {description: '"><b>'},
72
- csp_connect_src: ['wss://a" onload="x']
87
+ csp_connect_src: ['wss://a"onload="x']
73
88
  });
74
89
  expect(html).not.toContain("<script>");
75
90
  expect(html).toContain("&lt;/title&gt;&lt;script&gt;");
76
91
  expect(html).not.toContain('content=""><b>"');
77
- expect(html).not.toContain('wss://a" onload');
92
+ expect(html).not.toContain('wss://a"onload');
78
93
  });
79
94
  });
@@ -22,8 +22,8 @@ if(typeof globalThis.matchMedia === "undefined") {
22
22
  const {
23
23
  SDATA_END, gclass_create,
24
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,
25
+ gobj_start, gobj_read_attr, gobj_send_event, gobj_full_name,
26
+ set_log_callback, set_strings_are_text,
27
27
  } = await import("@yuneta/gobj-js");
28
28
  const {register_c_yui_window} = await import("./c_yui_window.js");
29
29
  const {register_c_yui_window_manager} = await import("./c_yui_window_manager.js");
@@ -73,11 +73,58 @@ describe("EV_SHOW", () => {
73
73
  gobj_start(w);
74
74
  const $w = gobj_read_attr(w, "$container");
75
75
 
76
- gobj_send_event(dock, "EV_MINIMIZE_WINDOW", {window: w}, w);
76
+ gobj_send_event(dock, "EV_MINIMIZE_WINDOW", {window: gobj_full_name(w)}, w);
77
77
  expect($w.style.getPropertyValue("display")).toBe("none");
78
78
 
79
79
  gobj_send_event(w, "EV_SHOW", {}, yuno);
80
80
  expect($w.style.getPropertyValue("display")).toBe("");
81
81
  expect(errors()).toEqual([]);
82
82
  });
83
+
84
+ test("the dock's events carry the window's NAME, plain json; the gobj is the src", () => {
85
+ const dock = gobj_create_service("name_dock", "C_YUI_WINDOW_MANAGER", {}, yuno);
86
+ gobj_start(dock);
87
+ const w = gobj_create_service("name_w", "C_YUI_WINDOW",
88
+ {header: "w", body: ["div", {}, "w"], manager: dock}, yuno);
89
+ gobj_start(w);
90
+ const $w = gobj_read_attr(w, "$container");
91
+
92
+ /* What the window itself sent to register is json. */
93
+ expect(dock.priv.windows.some((e) => e.gobj === w)).toBe(true);
94
+
95
+ /* A name that is not the src's is refused, loudly. */
96
+ logged.length = 0;
97
+ gobj_send_event(dock, "EV_MINIMIZE_WINDOW", {window: "someone^else"}, w);
98
+ expect($w.style.getPropertyValue("display")).toBe("");
99
+ expect(errors().some((m) => m.includes("is not the src"))).toBe(true);
100
+
101
+ /* The old form (the gobj in the kw) still works, with a warning. */
102
+ logged.length = 0;
103
+ gobj_send_event(dock, "EV_MINIMIZE_WINDOW", {window: w}, w);
104
+ expect($w.style.getPropertyValue("display")).toBe("none");
105
+ expect(errors()).toEqual([]);
106
+ expect(logged.some((l) => l.level === "warning" && l.msg.includes("gobj_full_name"))).toBe(true);
107
+ });
108
+
109
+ test("with plain strings as TEXT (set_strings_are_text) the controls are still svg", () => {
110
+ set_strings_are_text(true);
111
+ try {
112
+ logged.length = 0;
113
+ const dock = gobj_create_service("strict_dock", "C_YUI_WINDOW_MANAGER", {}, yuno);
114
+ gobj_start(dock);
115
+ const w = gobj_create_service("strict_w", "C_YUI_WINDOW",
116
+ {header: "w", body: ["div", {}, "w"], manager: dock}, yuno);
117
+ gobj_start(w);
118
+ const $w = gobj_read_attr(w, "$container");
119
+ for(const cls of ["wc-min", "wc-max", "wc-close"]) {
120
+ const $b = $w.querySelector(`.yui-wc.${cls}`);
121
+ expect($b, cls).not.toBe(null);
122
+ expect($b.textContent.includes("<svg"), cls).toBe(false);
123
+ expect($b.querySelector("svg"), cls).not.toBe(null);
124
+ }
125
+ expect(logged.some((l) => l.msg.includes("html_markup"))).toBe(false);
126
+ } finally {
127
+ set_strings_are_text(false);
128
+ }
129
+ });
83
130
  });
package/src/yui_asset.js CHANGED
@@ -20,6 +20,7 @@ import {
20
20
  } from "@yuneta/gobj-js";
21
21
 
22
22
  import {t} from "i18next";
23
+ import {text_node} from "./yui_text.js";
23
24
 
24
25
  import "./yui_asset.css";
25
26
 
@@ -357,10 +358,10 @@ function yui_asset_element(answer, opts = {})
357
358
 
358
359
  if(kind === "other") {
359
360
  const children = [
360
- ["span", {class: "ASSET_OTHER_TYPE"}, String(answer.content_type || "?")]
361
+ ["span", {class: "ASSET_OTHER_TYPE"}, text_node(answer.content_type || "?")]
361
362
  ];
362
363
  if(opts.detail) {
363
- children.push(["span", {class: "ASSET_OTHER_DETAIL"}, String(opts.detail)]);
364
+ children.push(["span", {class: "ASSET_OTHER_DETAIL"}, text_node(opts.detail)]);
364
365
  }
365
366
  const $card = createElement2(["div", {class: `${cls} ASSET_OTHER`}, children]);
366
367
  const $open = yui_asset_open_link(answer);
@@ -0,0 +1,33 @@
1
+ /***********************************************************************
2
+ * yui_data_color.js
3
+ *
4
+ * A colour read from DATA, checked before it goes into markup.
5
+ *
6
+ * A card of the treedb graph is html, and the colour a user gave it
7
+ * (a `__graphs__` record) is written into its `style="..."`. A value
8
+ * like `red" onmouseover="...` would leave the attribute and run.
9
+ * Only the plain colour syntaxes pass -- hex, the rgb()/hsl()
10
+ * functions, a name -- and the browser, where it can, also checks
11
+ * that it is a colour.
12
+ *
13
+ * Copyright (c) 2026, ArtGins.
14
+ * All Rights Reserved.
15
+ ***********************************************************************/
16
+
17
+ const DATA_COLOR_RE = /^(#[0-9a-f]{3,8}|(rgb|rgba|hsl|hsla)\([0-9.,%\s/+-]+\)|[a-z]+)$/i;
18
+
19
+ /************************************************************
20
+ * `value` when it is a css colour, else null.
21
+ ************************************************************/
22
+ export function css_color_or_null(value)
23
+ {
24
+ if(typeof value !== "string" || !DATA_COLOR_RE.test(value)) {
25
+ return null;
26
+ }
27
+ if(typeof CSS !== "undefined" && CSS && typeof CSS.supports === "function") {
28
+ if(!CSS.supports("color", value)) {
29
+ return null;
30
+ }
31
+ }
32
+ return value;
33
+ }
@@ -0,0 +1,27 @@
1
+ /***********************************************************************
2
+ * yui_data_color.test.js
3
+ *
4
+ * A colour from data goes into a card's `style="..."`: only a
5
+ * colour passes.
6
+ *
7
+ * Copyright (c) 2026, ArtGins.
8
+ * All Rights Reserved.
9
+ ***********************************************************************/
10
+ import {describe, test, expect} from "vitest";
11
+ import {css_color_or_null} from "./yui_data_color.js";
12
+
13
+ describe("css_color_or_null", () => {
14
+ test("the colour syntaxes pass", () => {
15
+ for(const c of ["#abc", "#AABBCC", "#aabbcc80", "red", "rgb(1, 2, 3)",
16
+ "rgba(1,2,3,0.5)", "hsl(120 50% 50%)", "hsla(120, 50%, 50%, .2)"]) {
17
+ expect(css_color_or_null(c)).toBe(c);
18
+ }
19
+ });
20
+
21
+ test("anything that could leave the attribute does not", () => {
22
+ for(const c of ['red" onmouseover="x()', "red; background:url(x)", "url(x)",
23
+ "<b>", "red\"", "expression(alert(1))", "", " red", 5, null, {}]) {
24
+ expect(css_color_or_null(c)).toBe(null);
25
+ }
26
+ });
27
+ });
package/src/yui_dev.js CHANGED
@@ -640,7 +640,7 @@ function traffic_scalar_row(key, value)
640
640
 
641
641
  return ['div', {class: 'TRAFFIC_ROW'}, [
642
642
  ['span', {class: 'TRAFFIC_BULLET'}, '•'],
643
- ['span', {class: 'TRAFFIC_KEY'}, key + ':'],
643
+ ['span', {class: 'TRAFFIC_KEY'}, text_node(key + ':')],
644
644
  ['span', {}, val_children],
645
645
  ]];
646
646
  }
@@ -744,7 +744,7 @@ function traffic_value_node(key, value)
744
744
  if(count === 0) {
745
745
  return ['div', {class: 'TRAFFIC_ROW'}, [
746
746
  ['span', {class: 'TRAFFIC_BULLET'}, '•'],
747
- ['span', {class: 'TRAFFIC_KEY'}, key + ':'],
747
+ ['span', {class: 'TRAFFIC_KEY'}, text_node(key + ':')],
748
748
  ['span', {class: 'TRAFFIC_VAL t-empty'}, is_arr ? '[ ]' : '{ }'],
749
749
  ]];
750
750
  }
package/src/yui_text.js CHANGED
@@ -29,3 +29,15 @@ export function text_node(value)
29
29
  }
30
30
  return document.createTextNode(String(value).trim());
31
31
  }
32
+
33
+ /************************************************************
34
+ * A Tabulator `titleFormatter` that shows the column title as text.
35
+ *
36
+ * Tabulator puts a STRING title in with innerHTML, so a title taken
37
+ * from a schema (`header`, which the schema editor writes) is markup
38
+ * unless the column carries a formatter that returns a Node.
39
+ ************************************************************/
40
+ export function text_title_formatter(cell)
41
+ {
42
+ return text_node(cell.getValue());
43
+ }
@@ -13,7 +13,12 @@ import {install_dom_double} from "../test/dom_double.js";
13
13
  install_dom_double();
14
14
 
15
15
  const {createElement2} = await import("@yuneta/gobj-js");
16
- const {text_node} = await import("./yui_text.js");
16
+ const {
17
+ SDATA_END, gclass_create, gobj_start_up, gobj_create_yuno, gobj_create,
18
+ gobj_read_attr, set_log_callback
19
+ } = await import("@yuneta/gobj-js");
20
+ const {text_node, text_title_formatter} = await import("./yui_text.js");
21
+ const {register_c_yui_nav} = await import("./c_yui_nav.js");
17
22
  const {card_descriptor} = await import("./nav_cards_helpers.js");
18
23
 
19
24
  const EVIL = "<img src=x onerror=alert(1)>";
@@ -36,4 +41,27 @@ describe("text_node()", () => {
36
41
  expect($card.querySelector("img")).toBe(null);
37
42
  expect($card.textContent).toContain(EVIL);
38
43
  });
44
+
45
+ test("a Tabulator column titled from a schema `header` shows it as text", () => {
46
+ const $title = text_title_formatter({getValue: () => EVIL});
47
+ expect($title instanceof Text).toBe(true);
48
+ expect($title.textContent).toBe(EVIL);
49
+ });
50
+
51
+ test("the accordion nav shows a section named by a backend as text", async () => {
52
+ const i18next = (await import("i18next")).default;
53
+ await i18next.init({lng: "en", resources: {}});
54
+ gobj_start_up(null, null, null, null, null, null, null);
55
+ set_log_callback(() => {});
56
+ gclass_create("C_TEST_TEXT_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
57
+ register_c_yui_nav();
58
+ const yuno = gobj_create_yuno("text_yuno", "C_TEST_TEXT_HOST", {});
59
+ const nav = gobj_create("acc", "C_YUI_NAV", {
60
+ layout: "accordion",
61
+ menu_items: [{id: "h", name: EVIL, submenu: {items: [{id: "s", name: EVIL, route: "/s"}]}}]
62
+ }, yuno);
63
+ const $c = gobj_read_attr(nav, "$container");
64
+ expect($c.querySelector("img")).toBe(null);
65
+ expect($c.querySelector(".yui-accordion-head").textContent).toBe(EVIL);
66
+ });
39
67
  });
@@ -7,7 +7,8 @@
7
7
  * - <meta> tags from config.metadata
8
8
  * - Content-Security-Policy from config.csp_connect_src
9
9
  * (always emitted: connect-src 'self' alone when the
10
- * list is missing, with a warning)
10
+ * list is missing, with a warning; an entry that is
11
+ * not one CSP source -- a `;`, `,` or space -- is refused)
11
12
  *
12
13
  * Usage in vite.config.js (vendored copy):
13
14
  * import { yunetaHtmlPlugin } from "./src/gobj-ui/vite-plugin-yuneta-html.js";
@@ -107,6 +108,19 @@ export function yunetaHtmlPlugin(options = {}) {
107
108
  * attribute, where a quote would end it. */
108
109
  origins = config.csp_connect_src
109
110
  .filter(s => typeof s === "string" && !s.startsWith("_comment"))
111
+ .filter(s => {
112
+ /* One SOURCE of the CSP grammar: a `;` would
113
+ * open a new directive (`wss://a; base-uri *`),
114
+ * and a `,` or a space would add sources the
115
+ * entry does not name. */
116
+ if (/[;,\s]/.test(s)) {
117
+ console.error(
118
+ `❌ csp_connect_src entry refused, not a single source: ${JSON.stringify(s)}`
119
+ );
120
+ return false;
121
+ }
122
+ return true;
123
+ })
110
124
  .map(escape_html);
111
125
  } else {
112
126
  console.warn(