From 1e13cf15aea00d8e9932a85b84b22162c1f6ff77 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 15 Oct 2018 17:31:28 +0200 Subject: [PATCH] parseLocation: strip leading zeros from IDs :boom: --- parse/location.js | 6 ++++-- test/lib/validators.js | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/parse/location.js b/parse/location.js index 0303b8bb..200a90c1 100644 --- a/parse/location.js +++ b/parse/location.js @@ -4,6 +4,8 @@ const POI = 'P' const STATION = 'S' const ADDRESS = 'A' +const leadingZeros = /^0+/ + // todo: what is s.rRefL? const parseLocation = (profile, opt, {lines}, l) => { const res = {type: 'location'} @@ -15,7 +17,7 @@ const parseLocation = (profile, opt, {lines}, l) => { if (l.type === STATION) { const stop = { type: l.isMainMast ? 'station' : 'stop', - id: l.extId, + id: (l.extId || '').replace(leadingZeros, ''), name: l.name ? profile.parseStationName(l.name) : null, location: 'number' === typeof res.latitude ? res : null } @@ -39,7 +41,7 @@ const parseLocation = (profile, opt, {lines}, l) => { if (l.type === ADDRESS) res.address = l.name else res.name = l.name - if (l.type === POI) res.id = l.extId || null + if (l.type === POI) res.id = l.extId && l.extId.replace(leadingZeros, '') || null return res } diff --git a/test/lib/validators.js b/test/lib/validators.js index aeca31c3..05924449 100644 --- a/test/lib/validators.js +++ b/test/lib/validators.js @@ -40,11 +40,13 @@ const validateStop = (val, s, name = 'stop') => { station.type = 'station' s = Object.assign({station}, s) defaultValidators.stop(val, s, name) + // todo: check if s.id has leading zeros } const validatePoi = (val, poi, name = 'location') => { defaultValidators.location(val, poi, name) val.ref(val, poi.id, name + '.id') + // todo: check if s.id has leading zeros a.ok(poi.name, name + '.name must not be empty') }