BearND has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/343586 )
Change subject: mobile-sections: Percent-decode title in Parsoid head
......................................................................
mobile-sections: Percent-decode title in Parsoid head
Also bump mobile-sections patch number.
Bug: T159860
Change-Id: Ie9948b5cb6c7c67621c748f1669b701cb2a0000f
---
M lib/mobile-util.js
M lib/parsoid-access.js
M test/lib/parsoid/parsoid-access-test.js
3 files changed, 24 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps
refs/changes/86/343586/1
diff --git a/lib/mobile-util.js b/lib/mobile-util.js
index d31608d..260901e 100644
--- a/lib/mobile-util.js
+++ b/lib/mobile-util.js
@@ -7,7 +7,7 @@
mUtil.CONTENT_TYPES = {
- mobileSections: { name: 'mobile-sections', version: '0.9.2' },
+ mobileSections: { name: 'mobile-sections', version: '0.9.3' },
definition: { name: 'definition', version: '0.7.1' },
random: { name: 'random', version: '0.6.0' },
diff --git a/lib/parsoid-access.js b/lib/parsoid-access.js
index 8aaaf04..8e3604d 100644
--- a/lib/parsoid-access.js
+++ b/lib/parsoid-access.js
@@ -153,7 +153,7 @@
function getParsoidLinkTitle(doc) {
const href = doc.querySelector('html > head >
link[rel="dc:isVersionOf"]').getAttribute('href');
const baseUri = getBaseUri(doc);
- return href.replace(new RegExp(`^${baseUri}`), '');
+ return decodeURIComponent(href.replace(new RegExp(`^${baseUri}`), ''));
}
/**
diff --git a/test/lib/parsoid/parsoid-access-test.js
b/test/lib/parsoid/parsoid-access-test.js
index 4aee91f..d20a833 100644
--- a/test/lib/parsoid/parsoid-access-test.js
+++ b/test/lib/parsoid/parsoid-access-test.js
@@ -5,11 +5,23 @@
const parsoid = require('../../../lib/parsoid-access');
const html = '<body>text0<h2>foo</h2>text1<h3 id="mwBa">Funny section
!@#$%^&*()</h3>text2</body>';
-const headHtml
+const headHtml1
= `<html><head>
<base href="//en.wikipedia.org/wiki/"/>
<link rel="dc:isVersionOf"
href="//en.wikipedia.org/wiki/Hope_(painting)"/>
</head></html>`;
+const headHtml2
+ = `<html>
+ <head>
+ <base href="//test.wikipedia.org/wiki/"/>
+ <link rel="dc:isVersionOf"
+
href="//test.wikipedia.org/wiki/User%3ABSitzmann_(WMF)/MCS/Test/Title_with_%3A"/>
+ </head>
+ <body>
+ <a rel="mw:WikiLink"
href="./User:BSitzmann_(WMF)/MCS/Test/Title_with_:#Section_1"
+ id="mwDw">#Section 1</a>
+ </body>
+ </html>`;
describe('lib:parsoid', function() {
@@ -74,12 +86,18 @@
});
it('getBaseUri()', () => {
- const doc = domino.createDocument(headHtml);
+ const doc = domino.createDocument(headHtml1);
assert.equal(parsoid._getBaseUri(doc), '//en.wikipedia.org/wiki/');
});
- it('getParsoidLinkTitle()', () => {
- const doc = domino.createDocument(headHtml);
+ it('getParsoidLinkTitle should return DB title', () => {
+ const doc = domino.createDocument(headHtml1);
assert.equal(parsoid._getParsoidLinkTitle(doc), 'Hope_(painting)');
});
+
+ it('getParsoidLinkTitle should percent-decode title', () => {
+ const doc = domino.createDocument(headHtml2);
+ assert.equal(parsoid._getParsoidLinkTitle(doc),
+ 'User:BSitzmann_(WMF)/MCS/Test/Title_with_:');
+ });
});
--
To view, visit https://gerrit.wikimedia.org/r/343586
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie9948b5cb6c7c67621c748f1669b701cb2a0000f
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