Skip to content

Commit

Permalink
Trim excess whitespace from node textContent
Browse files Browse the repository at this point in the history
  • Loading branch information
jahilldev committed Jan 12, 2022
1 parent be8f26f commit 0b58705
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function getDocument(html: string) {

function convertToVDom(this: CustomElement, node: Element) {
if (node.nodeType === 3) {
return node.textContent || '';
return node.textContent?.trim() || '';
}

if (node.nodeType !== 1) {
Expand Down
3 changes: 2 additions & 1 deletion tests/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ describe('parse', () => {
const result = parseHtml.call({ innerHTML: testWhitespace });
const instance = mount(h(result, {}) as any);

expect(instance.text()).toEqual(testWhitespace);
expect(instance.text()).toEqual('');
expect(instance.html()).toEqual('');
});

it('removes script blocks for security', () => {
Expand Down

0 comments on commit 0b58705

Please sign in to comment.