jenkins-bot has submitted this change and it was merged.
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(-)
Approvals:
BearND: Looks good to me, approved
Mholloway: Looks good to me, but someone else must approve
jenkins-bot: Verified
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 dd3893e..572a515 100644
--- a/test/features/mobile-sections-lead/pagecontent.js
+++ b/test/features/mobile-sections-lead/pagecontent.js
@@ -71,6 +71,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/Gogland' })
+ .then(function(res) {
+ var lead = res.body;
+ assert.ok(!lead.hasOwnProperty('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: merged
Gerrit-Change-Id: I22606b85bd60e1cc46105eae4b18e7be86d02ef4
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Dbrant <[email protected]>
Gerrit-Reviewer: Fjalapeno <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: Jhernandez <[email protected]>
Gerrit-Reviewer: Mholloway <[email protected]>
Gerrit-Reviewer: Mhurd <[email protected]>
Gerrit-Reviewer: Mobrovac <[email protected]>
Gerrit-Reviewer: Niedzielski <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits