From eae747a8a48b8816432ce5dde0f27ac9244fe890 Mon Sep 17 00:00:00 2001 From: boldtrn Date: Tue, 26 Sep 2023 09:47:51 +0200 Subject: [PATCH] fix: incorrect polyline decoding Don't split static image encoded path on pipe or comma Signed-off-by: boldtrn --- src/serve_rendered.js | 18 +++--------------- test/static.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/serve_rendered.js b/src/serve_rendered.js index ee0a5b7..27fbeae 100644 --- a/src/serve_rendered.js +++ b/src/serve_rendered.js @@ -162,21 +162,9 @@ const extractPathsFromQuery = (query, transformer) => { providedPath.includes('enc:') && PATH_PATTERN.test(decodeURIComponent(providedPath)) ) { - const encodedPaths = providedPath.split(','); - for (const path of encodedPaths) { - const line = path - .split('|') - .filter( - (x) => - !x.startsWith('fill') && - !x.startsWith('stroke') && - !x.startsWith('width'), - ) - .join('') - .replace('enc:', ''); - const coords = polyline.decode(line).map(([lat, lng]) => [lng, lat]); - paths.push(coords); - } + const encodedPaths = providedPath.replace('enc:', ''); + const coords = polyline.decode(encodedPaths).map(([lat, lng]) => [lng, lat]); + paths.push(coords); } else { // Iterate through paths, parse and validate them const currentPath = []; diff --git a/test/static.js b/test/static.js index 547d673..885543c 100644 --- a/test/static.js +++ b/test/static.js @@ -171,6 +171,18 @@ describe('Static endpoints', function () { '?path=-10,-10|-20,-20', ); }); + + describe('encoded path', function () { + testStatic( + prefix, + 'auto/20x20', + 'png', + 200, + 2, + /image\/png/, + '?path='+decodeURIComponent('enc:{{biGwvyGoUi@s_A|{@'), + ); + }); }); describe('invalid requests return 4xx', function () {