jenkins-bot has submitted this change and it was merged.
Change subject: Fix wikitext->pagebundle crasher when body_only is set
......................................................................
Fix wikitext->pagebundle crasher when body_only is set
* Another follow up to 39e10ae
* We had a wikitext->html test for body_only, but not one
for wikitext->pagebundle when body_only wa set.
* Added a new mocha test to catch this in future refactorings.
Change-Id: Ic65aad8cb2d1937d3bb4053eab1b44ae96419206
---
M lib/utils/DOMUtils.js
M tests/mocha/api.js
2 files changed, 29 insertions(+), 3 deletions(-)
Approvals:
Arlolra: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/utils/DOMUtils.js b/lib/utils/DOMUtils.js
index 2caeb0b..f7a944b 100644
--- a/lib/utils/DOMUtils.js
+++ b/lib/utils/DOMUtils.js
@@ -2297,7 +2297,7 @@
DOMUtils.extractDpAndSerialize = function(node, options) {
if (!options) { options = {}; }
options.captureOffsets = true;
- var dpScriptElt = node.getElementById('mw-data-parsoid');
+ var dpScriptElt = (DU.isBody(node) ? node.ownerDocument :
node).getElementById('mw-data-parsoid');
dpScriptElt.parentNode.removeChild(dpScriptElt);
var out = XMLSerializer.serialize(node, options);
out.dp = JSON.parse(dpScriptElt.text);
diff --git a/tests/mocha/api.js b/tests/mocha/api.js
index 42d8902..0ba614b 100644
--- a/tests/mocha/api.js
+++ b/tests/mocha/api.js
@@ -462,7 +462,7 @@
.end(done);
});
- it("should respect body parameter (body_only)",
function(done) {
+ it("should respect body parameter in wikitext->html
(body_only)", function(done) {
request(api)
.post(version === 3 ?
mockDomain +
'/v3/transform/wikitext/to/html/' :
@@ -488,7 +488,33 @@
.end(done);
});
- it("should respect body parameter (bodyOnly)",
function(done) {
+ it("should respect body parameter in
wikitext->pagebundle requests (body_only)", function(done) {
+ request(api)
+ .post(version === 3 ?
+ mockDomain +
'/v3/transform/wikitext/to/pagebundle/' :
+ 'v2/' + mockDomain + '/pagebundle/')
+ .send(version === 3 ? {
+ wikitext: "''foo''",
+ body_only: 1,
+ } : {
+ wikitext: "''foo''",
+ body: 1,
+ })
+ .expect(validPageBundleResponse())
+ .expect(function(res) {
+ if (version === 3) {
+ // v3 only returns children of
<body>
+
res.body.html.body.should.not.match(/<body/);
+
res.body.html.body.should.match(/<p/);
+ } else {
+ // v2 returns body and children
+
res.body.html.body.should.match(/^<body/);
+ }
+ })
+ .end(done);
+ });
+
+ it("should respect body parameter - b/c test for
bodyOnly", function(done) {
request(api)
.post(version === 3 ?
mockDomain +
'/v3/transform/wikitext/to/html/' :
--
To view, visit https://gerrit.wikimedia.org/r/286247
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic65aad8cb2d1937d3bb4053eab1b44ae96419206
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits