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:
parent
c13e5e6821
commit
eae747a8a4
2 changed files with 15 additions and 15 deletions
|
|
@ -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
|
paths.push(coords);
|
||||||
.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);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Iterate through paths, parse and validate them
|
// Iterate through paths, parse and validate them
|
||||||
const currentPath = [];
|
const currentPath = [];
|
||||||
|
|
|
||||||
|
|
@ -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 () {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue