Skip to content

Commit 2dfffb3

Browse files
Fix error for client-side parser by improving regex
For the client parser, when the first element of the HTML string has attributes, the regex will improperly capture everything and make the tag name invalid. The fix is to ensure only the tag name is matched and whitespace is trimmed. Fixes #23
1 parent 1774d2c commit 2dfffb3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/html-to-dom-client.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,14 @@ function formatDOM(nodes, parentNode) {
102102
* @return {Object} - The DOM nodes.
103103
*/
104104
function htmlToDOMClient(html) {
105-
var match = typeof html === 'string' ? html.match(/<(.+?)>/) : null;
105+
// from `<p>` or `<p style="">` get `p`
106+
var match = typeof html === 'string' ? html.match(/<(.+?)[>\s]/) : null;
106107
var tagName;
107108
var parentNode;
108109
var nodes;
109110

110111
if (match && typeof match[1] === 'string') {
111-
tagName = match[1].toLowerCase();
112+
tagName = match[1].trim().toLowerCase();
112113
}
113114

114115
// `DOMParser` can parse full HTML

0 commit comments

Comments
 (0)