From 1917dd76b5b92bc7379f5402774d73eace684220 Mon Sep 17 00:00:00 2001 From: Leon Sorokin Date: Wed, 20 Mar 2019 02:50:15 -0500 Subject: [PATCH] parse value-less attributes --- src/index.ts | 4 ++-- test/html.js | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index ec7c0e5..ec18ed7 100755 --- a/src/index.ts +++ b/src/index.ts @@ -460,10 +460,10 @@ export class HTMLElement extends Node { return this._rawAttrs; const attrs = {} as RawAttributes; if (this.rawAttrs) { - const re = /\b([a-z][a-z0-9\-]*)\s*=\s*("([^"]+)"|'([^']+)'|(\S+))/ig; + const re = /\b([a-z][a-z0-9\-]*)(?:\s*=\s*(?:"([^"]+)"|'([^']+)'|(\S+)))?/ig; let match: RegExpExecArray; while (match = re.exec(this.rawAttrs)) { - attrs[match[1]] = match[3] || match[4] || match[5]; + attrs[match[1]] = match[2] || match[3] || match[4] || ""; } } this._rawAttrs = attrs; diff --git a/test/html.js b/test/html.js index 22bed80..7f5dc02 100644 --- a/test/html.js +++ b/test/html.js @@ -264,11 +264,12 @@ describe('HTML Parser', function () { describe('#attributes', function () { it('should return attributes of the element', function () { - var root = parseHTML('

'); + var root = parseHTML('

'); root.firstChild.attributes.should.eql({ 'a': '12', 'data-id': '!$$&', - 'yAz': '1' + 'yAz': '1', + 'disabled': '' }); }); });