Skip to content

Commit

Permalink
$.parseHTML: ensuring whitespace around a single HTML tag is preserved
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiospampinato committed Dec 30, 2019
1 parent 95a9e7a commit 9c571dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/parse_html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface CashStatic {
}

const fragmentRe = /^\s*<(\w+)[^>]*>/,
singleTagRe = /^\s*<(\w+)\s*\/?>(?:<\/\1>)?\s*$/;
singleTagRe = /^<(\w+)\s*\/?>(?:<\/\1>)?$/;

const containers = {
'*': div,
Expand Down
17 changes: 17 additions & 0 deletions test/modules/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,23 @@ describe ( 'Utilities', function () {

});

it ( 'preserves leading/trailing whitespace', function ( t ) {

var htmls = [
' <b>foo</b>',
'<b>foo</b> ',
' <b>foo</b> ',
' <div></div>',
'<div></div> ',
' <div></div> '
];

htmls.forEach ( function ( html ) {
t.is ( $('<div>').append ( $.parseHTML ( html ) ).html (), html );
});

});

it ( 'doesn\'t overwrite previous DOM nodes', function ( t ) {

var span = $('<span>CONTENT</span>');
Expand Down

0 comments on commit 9c571dc

Please sign in to comment.