Arlolra has uploaded a new change for review.

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

Change subject: Handle coercion of the empty string in the API
......................................................................

Handle coercion of the empty string in the API

 * Fixes the error on kowiki/이완구 whose content is the empty string.
   That led to API returning a 302 redirect which the roundtrip-test.js
   doesn't follow but tries to return an error with res.body, which is
   undefined, tricking us into believing there is no err, setting the
   html as null and resending that to API which wasn't expecting it.

Change-Id: I5ea38deea0816f95cd6bfb6e7fbfcbec2c4f319a
---
M api/routes.js
M tests/roundtrip-test.js
2 files changed, 7 insertions(+), 5 deletions(-)


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

diff --git a/api/routes.js b/api/routes.js
index 1016c36..d411066 100644
--- a/api/routes.js
+++ b/api/routes.js
@@ -503,7 +503,7 @@
        }
 
        var p;
-       if ( wt && (!res.local('pageName') || !oldid) ) {
+       if ( typeof wt === 'string' && (!res.local('pageName') || !oldid) ) {
                // don't fetch the page source
                env.setPageSrcInfo( wt );
                p = Promise.resolve();
@@ -511,7 +511,7 @@
                p = promiseTemplateReq( env, target, oldid );
        }
 
-       if ( wt ) {
+       if ( typeof wt === 'string' ) {
                p = p.then( parseWt )
                        .timeout( REQ_TIMEOUT )
                        .then(sendRes);
@@ -833,7 +833,7 @@
                // Accept wikitext as a string or object{body,headers}
                var wikitext = (v2.wikitext && typeof v2.wikitext !== "string") 
?
                        v2.wikitext.body : v2.wikitext;
-               if ( !wikitext ) {
+               if ( typeof wikitext !== "string" ) {
                        if ( !res.local('pageName') ) {
                                return errOut( "No title or wikitext was 
provided.", 400 );
                        }
@@ -849,7 +849,8 @@
                        return errOut( "No html was supplied.", 400 );
                }
                // Accept html as a string or object{body,headers}
-               var html = (typeof v2.html === "string") ? v2.html : 
v2.html.body;
+               var html = (typeof v2.html === "string") ?
+                       v2.html : (v2.html.body || "");
                html2wt( req, res, html );
        }
 };
diff --git a/tests/roundtrip-test.js b/tests/roundtrip-test.js
index 7d010a6..d5d1a53 100755
--- a/tests/roundtrip-test.js
+++ b/tests/roundtrip-test.js
@@ -482,7 +482,8 @@
                if (err) {
                        cb( err, null );
                } else if (res.statusCode !== 200) {
-                       cb(res.body, null);
+                       err = new Error('Got status code: ' + res.statusCode);
+                       cb(err, null);
                } else {
                        var resBody, resDP;
                        if (oldid) {

-- 
To view, visit https://gerrit.wikimedia.org/r/202751
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5ea38deea0816f95cd6bfb6e7fbfcbec2c4f319a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>

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

Reply via email to