Skip to content

Commit

Permalink
Merge pull request #1020 from capricorn86/task/999-innerhtml-parser-i…
Browse files Browse the repository at this point in the history
…nterprets-in-unquoted-element-attributes-incorrectly

#999@patch: Adds support for URLs in attributes that doesn't use apos…
  • Loading branch information
capricorn86 authored Aug 18, 2023
2 parents 059d382 + 3103e1f commit 01fec13
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/happy-dom/src/xml-parser/XMLParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const MARKUP_REGEXP =
* Group 9: Attribute name when the attribute has no value (e.g. "disabled" in "<div disabled>").
*/
const ATTRIBUTE_REGEXP =
/\s*([a-zA-Z0-9-_:.$@?]+) *= *([a-zA-Z0-9-_:.$@?{}]+)|\s*([a-zA-Z0-9-_:.$@?]+) *= *"([^"]*)("{0,1})|\s*([a-zA-Z0-9-_:.$@?]+) *= *'([^']*)('{0,1})|\s*([a-zA-Z0-9-_:.$@?]+)/gm;
/\s*([a-zA-Z0-9-_:.$@?]+) *= *([a-zA-Z0-9-_:.$@?{}/]+)|\s*([a-zA-Z0-9-_:.$@?]+) *= *"([^"]*)("{0,1})|\s*([a-zA-Z0-9-_:.$@?]+) *= *'([^']*)('{0,1})|\s*([a-zA-Z0-9-_:.$@?]+)/gm;

enum MarkupReadStateEnum {
startOrEndTag = 'startOrEndTag',
Expand Down
8 changes: 8 additions & 0 deletions packages/happy-dom/test/xml-parser/XMLParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,14 @@ describe('XMLParser', () => {
);
});

it('Parses attributes with URL without apostrophs.', () => {
const root = XMLParser.parse(document, `<a href=http://www.github.com/path>Click me</a>`);

expect(new XMLSerializer().serializeToString(root)).toBe(
'<a href="http://www.github.com/path">Click me</a>'
);
});

it('Parses attributes with single apostrophs.', () => {
const root = XMLParser.parse(document, `<div key1='value1' key2='value2'>Test</div>`);

Expand Down

0 comments on commit 01fec13

Please sign in to comment.