forked from ashi009/node-fast-html-parser
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #62 - Escape double quotes in attribute values
Currently double quotes (") are not escaped in attribute values causing those attributes not to be set correctly. This commit replaces double quotes with `"`.
- Loading branch information
1 parent
6434743
commit e9ec888
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"}]', | ||
}); | ||
}); | ||
}); |