jenkins-bot has submitted this change and it was merged.
Change subject: Don't crash on images in subpages, or images with invalid
titles.
......................................................................
Don't crash on images in subpages, or images with invalid titles.
Change-Id: I78fdecc7b5529fe22943809c72b57dae55faab0c
---
M lib/image.js
M lib/parsoid.js
A samples/subpage.json
M test/samples.js
4 files changed, 133 insertions(+), 2 deletions(-)
Approvals:
Arlolra: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/image.js b/lib/image.js
index 0544d72..31c5891 100644
--- a/lib/image.js
+++ b/lib/image.js
@@ -59,6 +59,10 @@
if (resp.missing !== undefined && !resp.imagerepository) {
img.missing = true;
img.imageinfo = {};
+ } else if (resp.invalid !== undefined) {
+ console.error("Invalid title:", resp.title);
+ img.missing = true;
+ img.imageinfo = {};
} else {
img.imageinfo = resp.imageinfo[0];
}
diff --git a/lib/parsoid.js b/lib/parsoid.js
index 1259e54..19e9caa 100644
--- a/lib/parsoid.js
+++ b/lib/parsoid.js
@@ -76,7 +76,7 @@
var srcURL = url.resolve(base, img.getAttribute('src')); //
thumb, etc
return {
wiki: this.wiki,
- short: relResourceURL.replace(/^.\//, ''),
+ short: relResourceURL.replace(/^\.+\//, ''),
resource: resourceURL,
src: srcURL,
imagesize: this.imagesize
diff --git a/samples/subpage.json b/samples/subpage.json
new file mode 100644
index 0000000..d9754ef
--- /dev/null
+++ b/samples/subpage.json
@@ -0,0 +1,126 @@
+{
+ "type": "collection",
+ "licenses": [
+ {
+ "type": "license",
+ "name": "Лицензия",
+ "mw_rights_icon": "//creativecommons.org/images/public/somerights20.png",
+ "mw_rights_page": null,
+ "mw_rights_url": "//creativecommons.org/licenses/by-sa/3.0/",
+ "mw_rights_text": "Creative Commons Attribution-Share Alike 3.0"
+ }
+ ],
+ "title": "",
+ "subtitle": "",
+ "settings": [],
+ "items": [
+ {
+ "type": "article",
+ "content_type": "text/x-wiki",
+ "title": "Фелица (Державин)",
+ "revision": "1113587",
+ "latest": "1113587",
+ "timestamp": "1385315723",
+ "url":
"http://ru.wikisource.org/wiki/%D0%A4%D0%B5%D0%BB%D0%B8%D1%86%D0%B0_(%D0%94%D0%B5%D1%80%D0%B6%D0%B0%D0%B2%D0%B8%D0%BD)",
+ "currentVersion": 1
+ },
+ {
+ "type": "article",
+ "content_type": "text/x-wiki",
+ "title": "Восточная легенда (Тургенев)",
+ "revision": "459155",
+ "latest": "459155",
+ "timestamp": "1294427460",
+ "url":
"http://ru.wikisource.org/wiki/%D0%92%D0%BE%D1%81%D1%82%D0%BE%D1%87%D0%BD%D0%B0%D1%8F_%D0%BB%D0%B5%D0%B3%D0%B5%D0%BD%D0%B4%D0%B0_(%D0%A2%D1%83%D1%80%D0%B3%D0%B5%D0%BD%D0%B5%D0%B2)",
+ "currentVersion": 1
+ },
+ {
+ "type": "article",
+ "content_type": "text/x-wiki",
+ "title": "Хождение за три моря Афанасия Никитина",
+ "revision": "1207083",
+ "latest": "1207083",
+ "timestamp": "1407815650",
+ "url":
"http://ru.wikisource.org/wiki/%D0%A5%D0%BE%D0%B6%D0%B4%D0%B5%D0%BD%D0%B8%D0%B5_%D0%B7%D0%B0_%D1%82%D1%80%D0%B8_%D0%BC%D0%BE%D1%80%D1%8F_%D0%90%D1%84%D0%B0%D0%BD%D0%B0%D1%81%D0%B8%D1%8F_%D0%9D%D0%B8%D0%BA%D0%B8%D1%82%D0%B8%D0%BD%D0%B0",
+ "currentVersion": 1
+ },
+ {
+ "type": "article",
+ "content_type": "text/x-wiki",
+ "title": "Корсар (Лермонтов)",
+ "revision": "617121",
+ "latest": "617121",
+ "timestamp": "1317053037",
+ "url":
"http://ru.wikisource.org/wiki/%D0%9A%D0%BE%D1%80%D1%81%D0%B0%D1%80_(%D0%9B%D0%B5%D1%80%D0%BC%D0%BE%D0%BD%D1%82%D0%BE%D0%B2)",
+ "currentVersion": 1
+ },
+ {
+ "type": "article",
+ "content_type": "text/x-wiki",
+ "title": "Романтизм (Мицкевич/Минаев)",
+ "revision": "1146267",
+ "latest": "1146267",
+ "timestamp": "1388789065",
+ "url":
"http://ru.wikisource.org/wiki/%D0%A0%D0%BE%D0%BC%D0%B0%D0%BD%D1%82%D0%B8%D0%B7%D0%BC_(%D0%9C%D0%B8%D1%86%D0%BA%D0%B5%D0%B2%D0%B8%D1%87/%D0%9C%D0%B8%D0%BD%D0%B0%D0%B5%D0%B2)",
+ "currentVersion": 1
+ },
+ {
+ "type": "article",
+ "content_type": "text/x-wiki",
+ "title": "Бахчисарайский фонтан (Пушкин)",
+ "revision": "564897",
+ "latest": "564897",
+ "timestamp": "1307617494",
+ "url":
"http://ru.wikisource.org/wiki/%D0%91%D0%B0%D1%85%D1%87%D0%B8%D1%81%D0%B0%D1%80%D0%B0%D0%B9%D1%81%D0%BA%D0%B8%D0%B9_%D1%84%D0%BE%D0%BD%D1%82%D0%B0%D0%BD_(%D0%9F%D1%83%D1%88%D0%BA%D0%B8%D0%BD)",
+ "currentVersion": 1
+ },
+ {
+ "type": "article",
+ "content_type": "text/x-wiki",
+ "title": "Татарские песни (Полонский)/1",
+ "revision": "348545",
+ "latest": "348545",
+ "timestamp": "1266517171",
+ "url":
"http://ru.wikisource.org/wiki/%D0%A2%D0%B0%D1%82%D0%B0%D1%80%D1%81%D0%BA%D0%B8%D0%B5_%D0%BF%D0%B5%D1%81%D0%BD%D0%B8_(%D0%9F%D0%BE%D0%BB%D0%BE%D0%BD%D1%81%D0%BA%D0%B8%D0%B9)/1",
+ "currentVersion": 1
+ },
+ {
+ "type": "article",
+ "content_type": "text/x-wiki",
+ "title": "Иван Алексеевич Бунин",
+ "revision": "1205702",
+ "latest": "1205702",
+ "timestamp": "1407201609",
+ "url":
"http://ru.wikisource.org/wiki/%D0%98%D0%B2%D0%B0%D0%BD_%D0%90%D0%BB%D0%B5%D0%BA%D1%81%D0%B5%D0%B5%D0%B2%D0%B8%D1%87_%D0%91%D1%83%D0%BD%D0%B8%D0%BD",
+ "currentVersion": 1
+ },
+ {
+ "type": "article",
+ "content_type": "text/x-wiki",
+ "title": "Беглец (Лермонтов)",
+ "revision": "1165342",
+ "latest": "1165342",
+ "timestamp": "1393575829",
+ "url":
"http://ru.wikisource.org/wiki/%D0%91%D0%B5%D0%B3%D0%BB%D0%B5%D1%86_(%D0%9B%D0%B5%D1%80%D0%BC%D0%BE%D0%BD%D1%82%D0%BE%D0%B2)",
+ "currentVersion": 1
+ },
+ {
+ "type": "article",
+ "content_type": "text/x-wiki",
+ "title": "Тарас Бульба (Гоголь)/Глава I",
+ "revision": "992435",
+ "latest": "992435",
+ "timestamp": "1361303684",
+ "url":
"http://ru.wikisource.org/wiki/%D0%A2%D0%B0%D1%80%D0%B0%D1%81_%D0%91%D1%83%D0%BB%D1%8C%D0%B1%D0%B0_(%D0%93%D0%BE%D0%B3%D0%BE%D0%BB%D1%8C)/%D0%93%D0%BB%D0%B0%D0%B2%D0%B0_I",
+ "currentVersion": 1
+ }
+ ],
+ "wikis": [
+ {
+ "type": "wikiconf",
+ "baseurl": "//ru.wikisource.org/w",
+ "script_extension": ".php",
+ "format": "nuwiki"
+ }
+ ]
+}
diff --git a/test/samples.js b/test/samples.js
index 1fe91fe..fca16a9 100644
--- a/test/samples.js
+++ b/test/samples.js
@@ -17,7 +17,7 @@
// ensure that we don't crash on any of our sample inputs
describe("Basic crash test", function() {
- ['taoism.json', 'hurricanes.json',
'multiwiki.json'].forEach(function(name) {
+ ['taoism.json', 'hurricanes.json', 'multiwiki.json',
'subpage.json'].forEach(function(name) {
describe(name, function() {
it('should bundle', function() {
this.timeout(0);
@@ -28,6 +28,7 @@
metabook = JSON.parse(metabook);
return bundler.bundle(metabook,
{
output: filename +
'.zip',
+ parsoid:
'http://parsoid-lb.eqiad.wikimedia.org/',
size: IMAGESIZE,
debug: TRAVIS,
log: function() {
--
To view, visit https://gerrit.wikimedia.org/r/162289
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I78fdecc7b5529fe22943809c72b57dae55faab0c
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Collection/OfflineContentGenerator/bundler
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits