VBB: accept station IDs with unknown length 🐛

This commit is contained in:
Jannis R 2020-01-31 19:54:13 +01:00
parent db9287f7fd
commit 9b0e55c6ad
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5

View file

@ -86,14 +86,13 @@ const parseDepartureRenameRingbahn = ({parsed}) => {
const validIBNR = /^\d+$/ const validIBNR = /^\d+$/
const formatStation = (id) => { const formatStation = (id) => {
if ('string' !== typeof id) throw new Error('station ID must be a string.') if ('string' !== typeof id) throw new TypeError('station ID must be a string.')
const l = id.length if (!validIBNR.test(id)) {
if ((l !== 7 && l !== 9 && l !== 12) || !validIBNR.test(id)) {
throw new Error('station ID must be a valid IBNR.') throw new Error('station ID must be a valid IBNR.')
} }
// The VBB has some 7-digit stations. We don't convert them to 12 digits, // The VBB has some 7-digit stations. We don't convert them to 12 digits,
// because it only recognizes in the 7-digit format. see derhuerst/vbb-hafas#22 // because it only recognizes in the 7-digit format. see derhuerst/vbb-hafas#22
if (l !== 7) id = to9Digit(id) if (id.length !== 7) id = to9Digit(id)
return _formatStation(id) return _formatStation(id)
} }