@kubex/zinc 1.1.75 → 1.1.76

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubex/zinc",
3
- "version": "1.1.75",
3
+ "version": "1.1.76",
4
4
  "description": "A collection of web components for building web applications based off of @shoelace-style/Shoelace",
5
5
  "keywords": [
6
6
  "web components",
@@ -4,7 +4,6 @@ import {HasSlotController} from "../../internal/slot";
4
4
  import {html, unsafeCSS} from 'lit';
5
5
  import {MutationController} from '@lit-labs/observers/mutation-controller.js';
6
6
  import {property, queryAssignedNodes, queryAsync, state} from 'lit/decorators.js';
7
- import {unsafeHTML} from 'lit-html/directives/unsafe-html.js';
8
7
  import ZincElement from "../../internal/zinc-element";
9
8
  import type {PropertyValues} from 'lit';
10
9
  import type ZnTile from "../tile";
@@ -280,7 +279,7 @@ export default class ContentBlock extends ZincElement {
280
279
  'text-section--text': section.type === 'text',
281
280
  'hidden': section.type === 'reply'
282
281
  })}>
283
- ${section.lines.map((line) => html`${unsafeHTML(line)}<br>`)}
282
+ ${section.lines.map((line) => html`${line}<br>`)}
284
283
  </div>
285
284
  `)}
286
285
  </div>
@@ -375,7 +374,7 @@ export default class ContentBlock extends ZincElement {
375
374
  const textRows: TextRow[] = [];
376
375
 
377
376
  if (textContent) {
378
- const text = textContent.innerText;
377
+ const text = textContent.innerText.replace(/<br\s*\/?>/gi, '\n');
379
378
  const rows = text.split('\n');
380
379
  let previousType: TextRow['type'] | null = null;
381
380
  let forceReply = false;
@@ -1,10 +1,34 @@
1
1
  import '../../../dist/zn.min.js';
2
- import { expect, fixture, html } from '@open-wc/testing';
2
+ import { expect, fixture } from '@open-wc/testing';
3
+ import type { LitElement } from 'lit';
4
+
5
+ const textSection = async (body: string) => {
6
+ const el = await fixture<LitElement>(
7
+ `<zn-content-block><div slot="text">${body}</div></zn-content-block>`
8
+ );
9
+ await el.updateComplete;
10
+ return el.shadowRoot!.querySelector<HTMLDivElement>('.text-content')!;
11
+ };
3
12
 
4
13
  describe('<zn-content-block>', () => {
5
14
  it('should render a component', async () => {
6
- const el = await fixture(html` <zn-content-block></zn-content-block> `);
15
+ const el = await fixture('<zn-content-block></zn-content-block>');
7
16
 
8
17
  expect(el).to.exist;
9
18
  });
19
+
20
+ it('should render markup in the text body as text', async () => {
21
+ const content = await textSection('&lt;img src="x" onerror="window.__xss = true"&gt; hello');
22
+
23
+ expect(content.querySelector('img')).to.be.null;
24
+ expect(content.textContent).to.contain('<img src="x" onerror="window.__xss = true"> hello');
25
+ expect((window as unknown as Record<string, unknown>).__xss).to.be.undefined;
26
+ });
27
+
28
+ it('should treat escaped breaks in the text body as line breaks', async () => {
29
+ const content = await textSection('line1&lt;br /&gt;line2');
30
+
31
+ expect(content.textContent).to.not.contain('<br');
32
+ expect(content.querySelectorAll('br').length).to.be.greaterThan(1);
33
+ });
10
34
  });