Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/wcc.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ function renderLightDomChildren(childNodes, iHTML = '') {
? ''
: `</${nodeName}>`;
} else if (nodeName === '#text') {
innerHTML += value;
// TODO what about legitimate < content?
innerHTML += value.replace(/</g, '&lt;');
}
});

Expand Down
41 changes: 41 additions & 0 deletions test/cases/light-dom-html-entities/light-dom-html-entities.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Use Case
* Run wcc against HTML with Light DOM HTML entities in text nodes.
*
* User Result
* Should return the expected HTML with all the HTML entities preserved.
*
* User Workspace
* src/
* components/
* ctc-block.js
*/
import chai from 'chai';
import { renderFromHTML } from '../../../src/wcc.js';

const expect = chai.expect;

describe('Run WCC ', function() {
const LABEL = 'Using renderFromHTML with Light DOM HTML entities preserved';

describe(LABEL, function() {
let rawHtml;

before(async function() {
const { html } = await renderFromHTML(`
<x-ctc>
&#x3C;h1>Hello from the server rendered users page! 👋&#x3C;/h1>
</x-ctc>
`,
[
new URL('./src/components/ctc-block.js', import.meta.url)
]);

rawHtml = html;
});

it('should preserve HTML entities', function() {
expect(rawHtml).to.contain('&lt;h1&gt;Hello from the server rendered users page! 👋&lt;/h1&gt;');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default class CopyToClipboardBlock extends HTMLElement {

}

customElements.define('x-ctc', CopyToClipboardBlock);