Skip to content

Commit

Permalink
Fix my stupidity (and fix #84 as well)
Browse files Browse the repository at this point in the history
  • Loading branch information
inikulin committed Dec 12, 2015
1 parent efbf0cf commit a3f2ea8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/07_version_history.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Version history
## 2.0.2
* Fixed: yet another case of incorrect `parseFragment` arguments fallback (GH [#84](https://github.com/inikulin/parse5/issues/84)).

## 2.0.1
* Fixed: `parseFragment` arguments processing (GH [#82](https://github.com/inikulin/parse5/issues/82)).

Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ exports.parseFragment = function parseFragment(fragmentContext, html, options) {
if (typeof fragmentContext === 'string') {
options = html;
html = fragmentContext;
fragmentContext = null;
}

var parser = new Parser(options);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "parse5",
"description": "WHATWG HTML5 specification-compliant, fast and ready for production HTML parsing/serialization toolset for Node.js",
"version": "2.0.1",
"version": "2.0.2",
"author": "Ivan Nikulin <[email protected]> (https://github.com/inikulin)",
"contributors": [
"Alan Clarke (https://github.com/alanclarke)",
Expand Down
44 changes: 43 additions & 1 deletion test/fixtures/parser_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var assert = require('assert'),
path = require('path'),
parse5 = require('../../lib'),
Parser = require('../../lib/parser'),
testUtils = require('../test_utils');

function getFullTestName(test) {
Expand Down Expand Up @@ -44,7 +45,7 @@ testUtils.generateTestsForEachTreeAdapter(module.exports, function (_test, treeA
], treeAdapter)
.forEach(function (test) {
_test[getFullTestName(test)] = function () {
var opts = { treeAdapter: treeAdapter };
var opts = {treeAdapter: treeAdapter};


if (test.fragmentContext)
Expand All @@ -66,3 +67,44 @@ exports['Regression - HTML5 Legacy Doctype Misparsed with htmlparser2 tree adapt
assert.strictEqual(document.childNodes[0].data, '!DOCTYPE html SYSTEM "about:legacy-compat"');
};

var origParseFragment = Parser.prototype.parseFragment;

exports['Regression - Incorrect arguments fallback for the parser.parseFragment (GH-82, GH-83)'] = {
beforeEach: function () {
Parser.prototype.parseFragment = function (html, fragmentContext) {
return {
html: html,
fragmentContext: fragmentContext,
options: this.options
};
};
},

afterEach: function () {
Parser.prototype.parseFragment = origParseFragment;
},

test: function () {
var fragmentContext = parse5.treeAdapters.default.createElement('div'),
html = '<script></script>',
opts = {locationInfo: true};

var args = parse5.parseFragment(fragmentContext, html, opts);

assert.strictEqual(args.fragmentContext, fragmentContext);
assert.strictEqual(args.html, html);
assert(args.options.locationInfo);

args = parse5.parseFragment(html, opts);

assert(!args.fragmentContext);
assert.strictEqual(args.html, html);
assert(args.options.locationInfo);

args = parse5.parseFragment(html);

assert(!args.fragmentContext);
assert.strictEqual(args.html, html);
assert(!args.options.locationInfo);
}
};

0 comments on commit a3f2ea8

Please sign in to comment.