Arlolra has uploaded a new change for review.

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

Change subject: Preserve querystring params while redirecting
......................................................................

Preserve querystring params while redirecting

 * Also, have the v2 api respect the body param.

 * Discussion stems from,
   https://gerrit.wikimedia.org/r/#/c/201095/

Change-Id: I8616b62b768759fed839858f2464832ed993ee43
---
M api/routes.js
M tests/mocha/api.js
2 files changed, 32 insertions(+), 1 deletion(-)


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

diff --git a/api/routes.js b/api/routes.js
index 7533bb7..c84001a 100644
--- a/api/routes.js
+++ b/api/routes.js
@@ -3,6 +3,7 @@
 
 var path = require('path'),
        fs = require('fs'),
+       qs = require('querystring'),
        url = require('url'),
        util = require('util'),
        child_process = require('child_process'),
@@ -488,8 +489,13 @@
                } else {
                        path += [
                                prefix,
-                               encodeURIComponent( target ) + "?oldid=" + oldid
+                               encodeURIComponent( target )
                        ].join("/");
+                       req.query.oldid = oldid;
+               }
+
+               if ( Object.keys( req.query ).length > 0 ) {
+                       path += "?" + qs.stringify( req.query );
                }
 
                // Redirect to oldid
@@ -781,6 +787,9 @@
        res.local('pageName', req.params.title || '');
        res.local('oldid', req.params.revision || null);
 
+       // "body" flag to return just the body (instead of the entire HTML doc)
+       res.local('body', req.query.body || req.body.body);
+
        var v2 = Object.assign({ format: req.params.format }, req.body);
 
        if ( !supportedFormats.has( v2.format ) ||
diff --git a/tests/mocha/api.js b/tests/mocha/api.js
index bc98d98..e1ef016 100644
--- a/tests/mocha/api.js
+++ b/tests/mocha/api.js
@@ -87,6 +87,16 @@
                                .end(done);
                        });
 
+                       it("should preserve querystring params while 
redirecting", function(done) {
+                               request(api)
+                               .get('v2/' + mockHost + 
'/html/Main_Page?test=123')
+                               .expect(302)
+                               .expect(function(res) {
+                                       res.headers.location.should.match( 
/\/html\/Main_Page\/1\?test=123$/ );
+                               })
+                               .end(done);
+                       });
+
                        it("should get html from a title and revision", 
function(done) {
                                request(api)
                                .get('v2/' + mockHost + '/html/Main_Page/1')
@@ -254,6 +264,18 @@
                                .end(done);
                        });
 
+                       it("should respect body parameter", function (done) {
+                               request(api)
+                               .post('v2/' + mockHost + '/html/')
+                               .send({
+                                       wikitext: "''foo''",
+                                       body: 1
+                               })
+                               .expect(200)
+                               .expect(/^<body/)
+                               .end(done);
+                       });
+
                }); // end wt2html
 
                describe("html2wt", function() {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8616b62b768759fed839858f2464832ed993ee43
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