Subramanya Sastry has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/286247

Change subject: Fix wikitext->pagebundle crasher when body_only is set
......................................................................

Fix wikitext->pagebundle crasher when body_only is 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(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid 
refs/changes/47/286247/1

diff --git a/lib/utils/DOMUtils.js b/lib/utils/DOMUtils.js
index d777d43..41d3b0f 100644
--- a/lib/utils/DOMUtils.js
+++ b/lib/utils/DOMUtils.js
@@ -2300,7 +2300,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: newchange
Gerrit-Change-Id: Ic65aad8cb2d1937d3bb4053eab1b44ae96419206
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to