Skip to content

Commit

Permalink
#999@patch: Adds support for URLs in attributes that doesn't use apos…
Browse files Browse the repository at this point in the history
…trophs in XMLParser.
  • Loading branch information
capricorn86 committed Aug 18, 2023
1 parent 059d382 commit 3103e1f
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 3103e1f

Please sign in to comment.