Emit console warning when using an unsupported BRouter version

abrensch/brouter@c9ae7c8681 changed indexing of voice hint ids, because
some new hints were inserted in the middle instead of strictly at the
end, changing the numbering of existing ids. For example, now id `12`
was sent to indicate a right u-turn, while we still assume the old
meaning of `12`, i.e. "off route". This clearly was an API break.

This leads us to abort exporting with the Gpsies turn instructions
style, since `OFFR` has an `undefined` symbol assigned, as well as
emitting wrong voice hints for ids after `9`. Another unwelcome side
effect is showing negative exit numbers for roundabouts.

This breakage in the GeoJSON HTTP API has been shipping in BRouter 1.7.0
and 1.7.1 and finally got fixed with abrensch/brouter@82fecf9 contained
in BRouter 1.7.2 or later. Earlier releases like 1.6.3 are also
unaffected. To avoid emitting incorrect voice hints in BRouter-Web,
running with broken versions of BRouter should be avoided.

By checking the "Creator" field after receiving the first response from
BRouter, we can now emit a warning if the version of BRouter used is
unsupported. The warning mostly targets administrators and power users,
i.e. those responsible for choosing the software versions used, and it
is also only shown once per session.

Note that the version check is compatible with the common "SemVer"
scheme, so the check should continue working and even support more
complex version compatibility scenarios as long as BRouter stays
SemVer-compliant.

Ref #751

Test Plan:
  - Run with BRouter 1.6.3 and 1.7.2, no warnings shown.
  - Run with BRouter 1.7.0 and 1.7.1, warnings shown only for the first
  segment.
This commit is contained in:
Henrik Fehlauer 2023-07-06 09:46:47 +00:00
parent 3f241c9180
commit eeb1c5bde3
No known key found for this signature in database
GPG key ID: 177EECC0FF03B880
4 changed files with 40 additions and 0 deletions

View file

@ -148,3 +148,5 @@ Copyright (c) 2018 Norbert Renner and [contributors](https://github.com/nrenner/
Copyright (c) 2012 davidshimjs [The MIT License](https://github.com/llyys/qrcodejs/blob/master/LICENSE) Copyright (c) 2012 davidshimjs [The MIT License](https://github.com/llyys/qrcodejs/blob/master/LICENSE)
- [Bootstrap Icons](https://github.com/twbs/icons) - [Bootstrap Icons](https://github.com/twbs/icons)
Copyright (c) 2019-2023 The Bootstrap Authors [The MIT License](https://github.com/twbs/icons/blob/main/LICENSE) Copyright (c) 2019-2023 The Bootstrap Authors [The MIT License](https://github.com/twbs/icons/blob/main/LICENSE)
- [compare-versions](https://github.com/omichelsen/compare-versions)
Copyright (c) 2015-2021 Ole Michelsen [The MIT License](https://github.com/omichelsen/compare-versions/blob/main/LICENSE)

View file

@ -10,6 +10,7 @@ L.BRouter = L.Class.extend({
GROUP_SEPARATOR: '|', GROUP_SEPARATOR: '|',
ABORTED_ERROR: 'aborted', ABORTED_ERROR: 'aborted',
CUSTOM_PREFIX: 'custom_', CUSTOM_PREFIX: 'custom_',
SUPPORTED_BROUTER_VERSIONS: '< 1.7.0 || >=1.7.2', // compatibility string should be in npm package versioning format
isCustomProfile: function (profileName) { isCustomProfile: function (profileName) {
return profileName && profileName.substring(0, 7) === L.BRouter.CUSTOM_PREFIX; return profileName && profileName.substring(0, 7) === L.BRouter.CUSTOM_PREFIX;
}, },
@ -178,6 +179,7 @@ L.BRouter = L.Class.extend({
try { try {
geojson = JSON.parse(xhr.responseText); geojson = JSON.parse(xhr.responseText);
layer = this._assignFeatures(L.geoJSON(geojson).getLayers()[0]); layer = this._assignFeatures(L.geoJSON(geojson).getLayers()[0]);
this.checkBRouterVersion(layer.feature.properties.creator);
return cb(null, layer); return cb(null, layer);
} catch (e) { } catch (e) {
@ -189,6 +191,31 @@ L.BRouter = L.Class.extend({
} }
}, },
versionCheckDone: false,
checkBRouterVersion: function (creator) {
if (this.versionCheckDone) {
return;
}
this.versionCheckDone = true;
try {
const actualBRouterVersion = creator.replace(/^BRouter-/, '');
if (!compareVersions.satisfies(actualBRouterVersion, L.BRouter.SUPPORTED_BROUTER_VERSIONS)) {
console.warn(
'BRouter-Web ' +
BR.version +
' requires BRouter versions ' +
L.BRouter.SUPPORTED_BROUTER_VERSIONS +
', but only ' +
creator +
' was found.'
);
}
} catch (e) {
console.error(e);
}
},
getRouteSegment: function (l1, l2, cb) { getRouteSegment: function (l1, l2, cb) {
this.queue.push({ segment: [l1, l2] }, cb); this.queue.push({ segment: [l1, l2] }, cb);
}, },

View file

@ -49,6 +49,7 @@
"bootstrap-select": "1.13.18", "bootstrap-select": "1.13.18",
"bootstrap-slider": "11.0.2", "bootstrap-slider": "11.0.2",
"codemirror": "5.65.13", "codemirror": "5.65.13",
"compare-versions": "^6.0.0",
"core-js-bundle": "3.29.1", "core-js-bundle": "3.29.1",
"datatables": "1.10.18", "datatables": "1.10.18",
"fit-file-writer": "tbsmark86/fit-file-writer#3eebe13", "fit-file-writer": "tbsmark86/fit-file-writer#3eebe13",
@ -309,6 +310,11 @@
"index.js" "index.js"
] ]
}, },
"compare-versions": {
"main": [
"lib/umd/index.js"
]
},
"@mapbox/maki": { "@mapbox/maki": {
"main": [ "main": [
"icons/art-gallery.svg", "icons/art-gallery.svg",

View file

@ -4197,6 +4197,11 @@ commander@^9.0.0:
resolved "https://registry.yarnpkg.com/commander/-/commander-9.5.0.tgz#bc08d1eb5cedf7ccb797a96199d41c7bc3e60d30" resolved "https://registry.yarnpkg.com/commander/-/commander-9.5.0.tgz#bc08d1eb5cedf7ccb797a96199d41c7bc3e60d30"
integrity sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ== integrity sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==
compare-versions@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-6.0.0.tgz#a3edb527e4487bfab9a8b62ffe70cebc9b87675b"
integrity sha512-s2MzYxfRsE9f/ow8hjn7ysa7pod1xhHdQMsgiJtKx6XSNf4x2N1KG4fjrkUmXcP/e9Y2ZX4zB6sHIso0Lm6evQ==
component-emitter@^1.2.1: component-emitter@^1.2.1:
version "1.3.0" version "1.3.0"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0" resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0"