Skip to content

Commit

Permalink
feat: disable XML mode
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jul 14, 2018
1 parent bfad5ce commit 59fa847
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/evaluators/cheerioEvaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default (): EvaluatorType => {
const parseDocument = (subject) => {
return cheerio
.load(subject, {
xmlMode: true
xmlMode: false
})
.root();
};
Expand Down
14 changes: 14 additions & 0 deletions test/surgeon/evaluators/cheerioEvaluator/cheerio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @flow

import test from 'ava';
import cheerio from 'cheerio';

// @see https://github.com/cheeriojs/cheerio/issues/1211
// eslint-disable-next-line ava/no-skip-test
test.skip('returns innerHTML property value', (t) => {
const $ = cheerio.load('<script>"<br>"</script>', {
xmlMode: true
});

t.true($.html() === '<script>"<br>"</script>');
});
17 changes: 12 additions & 5 deletions test/surgeon/evaluators/cheerioEvaluator/getPropertyValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ test('returns outerHTML property value', (t) => {
t.true(getPropertyValue(node, 'outerHTML') === '<div>foo</div>');
});

test('returns outerHTML property value (table)', (t) => {
// This test is disabled as XML mode is breaking parsing of tags
// that contain unescaped tags within them.
// @see https://github.com/cheeriojs/cheerio/issues/1211
// eslint-disable-next-line ava/no-skip-test
test.skip('returns outerHTML property value (table)', (t) => {
const {
getPropertyValue,
parseDocument,
Expand All @@ -47,15 +51,18 @@ test('returns outerHTML property value (table)', (t) => {
t.true(getPropertyValue(nodes[0], 'outerHTML') === '<td>foo</td>');
});

test('returns innerHTML property value', (t) => {
test('returns outerHTML property value (tag within a tag)', (t) => {
const {
getPropertyValue,
parseDocument,
querySelectorAll
} = cheerioEvaluator();

const document = parseDocument('<div><span>foo</span></div>');
const node = querySelectorAll(document, 'div')[0];
const document = parseDocument('<script>"<br>"</script>');

const nodes = querySelectorAll(document, 'script');

t.true(nodes.length === 1);

t.true(getPropertyValue(node, 'innerHTML') === '<span>foo</span>');
t.true(getPropertyValue(nodes[0], 'outerHTML') === '<script>"<br>"</script>');
});

0 comments on commit 59fa847

Please sign in to comment.