Niedzielski has uploaded a new change for review.
https://gerrit.wikimedia.org/r/289329
Change subject: Fix geo prop
......................................................................
Fix geo prop
• Don't return a null geo property or geo with a null latitude or
longitude.
• Be more permissive in geo parser.
Bug: T135571
Change-Id: I22606b85bd60e1cc46105eae4b18e7be86d02ef4
---
M lib/parseProperty.js
M test/features/mobile-sections-lead/pagecontent.js
2 files changed, 24 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps
refs/changes/29/289329/1
diff --git a/lib/parseProperty.js b/lib/parseProperty.js
index 171745d..161b5bb 100644
--- a/lib/parseProperty.js
+++ b/lib/parseProperty.js
@@ -67,10 +67,11 @@
* @returns {Geo} if latitude or longitude is truthy, else undefined.
*/
function latLngStrToGeo(latLngStr) {
- var latLng = latLngStr && latLngStr.split('; ') || [];
- return latLng.length
- && { "latitude": latLng[0] && parseFloat(latLng[0]),
- "longitude": latLng[1] && parseFloat(latLng[1]) };
+ var latLng = latLngStr && latLngStr.split(/[;, ]+/) || [];
+ var geo = latLng.length &&
+ { latitude: latLng[0] && parseFloat(latLng[0]),
+ longitude: latLng[1] && parseFloat(latLng[1]) };
+ return mUtil.defaultVal(mUtil.filterEmpty(geo));
}
/**
@@ -78,7 +79,10 @@
*/
function parseGeo(lead, page) {
var coordinates = lead.querySelector('span#coordinates .geo');
- page.geo = coordinates && latLngStrToGeo(coordinates.innerHTML);
+ var geo = coordinates && latLngStrToGeo(coordinates.textContent);
+ if (geo) {
+ page.geo = geo;
+ }
}
/**
diff --git a/test/features/mobile-sections-lead/pagecontent.js
b/test/features/mobile-sections-lead/pagecontent.js
index 93c3d0f..9d933da 100644
--- a/test/features/mobile-sections-lead/pagecontent.js
+++ b/test/features/mobile-sections-lead/pagecontent.js
@@ -70,6 +70,21 @@
assert.deepEqual(lead.geo.longitude, -122.417);
});
});
+ it('es Savonlinna should have a lead object with a geo property',
function() {
+ return preq.get({ uri: server.config.uri +
'es.wikipedia.org/v1/page/mobile-sections-lead/Savonlinna' })
+ .then(function(res) {
+ var lead = res.body;
+ assert.deepEqual(lead.geo.latitude, 61.866666666667);
+ assert.deepEqual(lead.geo.longitude, 28.883055555556);
+ });
+ });
+ it('es Gogland should not have a lead object with a geo property',
function() {
+ return preq.get({ uri: server.config.uri +
'es.wikipedia.org/v1/page/mobile-sections-lead/Savonlinna' })
+ .then(function(res) {
+ var lead = res.body;
+ assert.ok(!lead.hasOwnProperty(lead.geo));
+ });
+ });
it('Barack Obama should have a pronunciation', function() {
return preq.get({ uri: server.config.uri +
'en.wikipedia.org/v1/page/mobile-sections-lead/Barack_Obama' })
.then(function(res) {
--
To view, visit https://gerrit.wikimedia.org/r/289329
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I22606b85bd60e1cc46105eae4b18e7be86d02ef4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits