forked from ashi009/node-fast-html-parser
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from lamplightdev/main
Fixes #62 - Escape double quotes in attribute values
- Loading branch information
Showing
2 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const { parse } = require('../dist'); | ||
|
||
// https://github.com/taoqf/node-html-parser/issues/62 | ||
describe('quote attributes', function () { | ||
it('escapes double quotes when using setAttribute', function () { | ||
const root = parse(`<div></div>`); | ||
const div = root.firstChild; | ||
div.setAttribute('foo', '[{"bar":"baz"}]'); | ||
div | ||
.toString() | ||
.should.eql('<div foo="[{"bar":"baz"}]"></div>'); | ||
}); | ||
|
||
it('escapes double quotes when using setAttributes', function () { | ||
const root = parse(`<div></div>`); | ||
const div = root.firstChild; | ||
div.setAttributes({ foo: '[{"bar":"baz"}]' }); | ||
div | ||
.toString() | ||
.should.eql('<div foo="[{"bar":"baz"}]"></div>'); | ||
}); | ||
|
||
it('parses attributes containing "', function () { | ||
const root = parse('<div foo="[{"bar":"baz"}]"></div>'); | ||
const div = root.firstChild; | ||
div.getAttribute('foo').should.eql('[{"bar":"baz"}]'); | ||
div.attributes.should.eql({ | ||
foo: '[{"bar":"baz"}]', | ||
}); | ||
}); | ||
}); |