fix: incorrect polyline decoding

Don't split static image encoded path on pipe or comma

Signed-off-by: boldtrn <boldtrn@gmail.com>
This commit is contained in:
boldtrn 2023-09-26 09:47:51 +02:00 committed by Andrew Calcutt
parent c13e5e6821
commit eae747a8a4
2 changed files with 15 additions and 15 deletions

View file

@ -162,21 +162,9 @@ const extractPathsFromQuery = (query, transformer) => {
providedPath.includes('enc:') && providedPath.includes('enc:') &&
PATH_PATTERN.test(decodeURIComponent(providedPath)) PATH_PATTERN.test(decodeURIComponent(providedPath))
) { ) {
const encodedPaths = providedPath.split(','); const encodedPaths = providedPath.replace('enc:', '');
for (const path of encodedPaths) { const coords = polyline.decode(encodedPaths).map(([lat, lng]) => [lng, lat]);
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); paths.push(coords);
}
} else { } else {
// Iterate through paths, parse and validate them // Iterate through paths, parse and validate them
const currentPath = []; const currentPath = [];

View file

@ -171,6 +171,18 @@ describe('Static endpoints', function () {
'?path=-10,-10|-20,-20', '?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 () { describe('invalid requests return 4xx', function () {