BearND has uploaded a new change for review.

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

Change subject: Decode entities when following redirects
......................................................................

Decode entities when following redirects

Bug: T131406
Change-Id: I5c44849f8c0760d3bd65f6426640e03d15e620f3
---
M lib/parsoid-access.js
M test/features/mobile-sections/pagecontent.js
M test/lib/parsoid/parsoid-access-test.js
3 files changed, 19 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps 
refs/changes/88/281588/1

diff --git a/lib/parsoid-access.js b/lib/parsoid-access.js
index 948a4fd..5edb840 100644
--- a/lib/parsoid-access.js
+++ b/lib/parsoid-access.js
@@ -7,6 +7,7 @@
 var preq = require('preq');
 var domino = require('domino');
 var a = require('./anchorencode');
+var Html5Entities = require('html-entities').Html5Entities;
 var Template = require('swagger-router').Template;
 var sUtil = require('../lib/util');
 var mwapi = require('./mwapi');
@@ -56,14 +57,16 @@
 }
 
 /**
- * Gets the redirected title from the Parsoid payload.
+ * Gets the redirected title from the Parsoid (HTML) payload.
+ * If there are any HTML entities inside the title string they get decoded.
  * Note: this assumes that hasRedirectInPayload returns true.
  *
  * @param {string} body the Parsoid response body to check for redirects
  * @return {string} the title of the redirect target or empty string.
  */
 function getRedirectTitleFromPayload(body) {
-    return REDIRECT_REGEXP.exec(body)[1];
+    var otherTitle = REDIRECT_REGEXP.exec(body)[1];
+    return Html5Entities.decode(otherTitle);
 }
 
 /**
@@ -286,5 +289,6 @@
     _addSectionDivs: addSectionDivs,
     _getSectionsText: getSectionsText,
     _getRedirectTitleFromLocationHeader: getRedirectTitleFromLocationHeader,
+    _getRedirectTitleFromPayload: getRedirectTitleFromPayload,
     _hasRedirectInPayload: hasRedirectInPayload
 };
diff --git a/test/features/mobile-sections/pagecontent.js 
b/test/features/mobile-sections/pagecontent.js
index f16084d..7e65564 100644
--- a/test/features/mobile-sections/pagecontent.js
+++ b/test/features/mobile-sections/pagecontent.js
@@ -126,4 +126,11 @@
                 assert.deepEqual(res.body.lead.spoken.files[0], 
'File:En-Alliterative_verse-article.ogg');
             });
     });
+    it('Page with HTML entity in redirected page title should load', 
function() {
+        return preq.get({ uri: server.config.uri + 
'test.wikipedia.org/v1/page/mobile-sections/User:BSitzmann_%28WMF%29%2FMCS%2FTest%2FA%26B_redirect'
 })
+            .then(function(res) {
+                assert.deepEqual(res.status, 200);
+                //assert.deepEqual(res.body.lead.spoken.files[0], 
'File:En-Alliterative_verse-article.ogg');
+            });
+    });
 });
diff --git a/test/lib/parsoid/parsoid-access-test.js 
b/test/lib/parsoid/parsoid-access-test.js
index 45f84f0..000d296 100644
--- a/test/lib/parsoid/parsoid-access-test.js
+++ b/test/lib/parsoid/parsoid-access-test.js
@@ -80,6 +80,12 @@
         assert.ok(redirect === false);
     });
 
+    it('_getRedirectTitleFromPayload(): HTML entities in redirected title 
should be decoded', function() {
+        var body = '<link rel="mw:PageProp/redirect" href="./some foo &amp; 
bar title"';
+        var actual = parsoid._getRedirectTitleFromPayload(body);
+        assert.deepEqual(actual, 'some foo & bar title');
+    });
+
     it('_getRedirectTitleFromLocationHeader() with redirect', function() {
         var response = {
             'status': 301,

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5c44849f8c0760d3bd65f6426640e03d15e620f3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: BearND <[email protected]>

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

Reply via email to