mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Fix decompression when floats are used, but no integers are present (#14985)
Fixes #14980
This commit is contained in:
@@ -20,6 +20,22 @@ const deep = {
|
||||
|
||||
const arr = ['directus', false, deep];
|
||||
|
||||
const geoJSON = {
|
||||
data: [
|
||||
{
|
||||
id: 'f36431ea-0d25-4747-8b37-185eb3ba66d0',
|
||||
point1: {
|
||||
type: 'Point',
|
||||
coordinates: [-107.57812499999984, 34.30714385628873],
|
||||
},
|
||||
point2: {
|
||||
type: 'Point',
|
||||
coordinates: [-91.25923790168956, 42.324763327278106],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
describe('compress', () => {
|
||||
test('Compresses plain objects', () => {
|
||||
expect(compress(plain)).toBe(
|
||||
@@ -39,6 +55,12 @@ describe('compress', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('Compresses GeoJSON format reliably', () => {
|
||||
expect(compress(geoJSON)).toBe(
|
||||
'data|id|f36431ea-0d25-4747-8b37-185eb3ba66d0|point1|type|Point|coordinates|point2^^-107.57812499999984|34.30714385628873|-91.25923790168956|42.324763327278106^$0|@$1|2|3|$4|5|6|@8|9]]|7|$4|5|6|@A|B]]]]]'
|
||||
);
|
||||
});
|
||||
|
||||
test('Throws error on non-supported types', () => {
|
||||
expect(() => compress({ method: () => true })).toThrowError();
|
||||
});
|
||||
@@ -69,6 +91,14 @@ describe('decompress', () => {
|
||||
).toEqual(arr);
|
||||
});
|
||||
|
||||
test('Decompresses GeoJSON properly', () => {
|
||||
expect(
|
||||
decompress(
|
||||
'data|id|f36431ea-0d25-4747-8b37-185eb3ba66d0|point1|type|Point|coordinates|point2^^-107.57812499999984|34.30714385628873|-91.25923790168956|42.324763327278106^$0|@$1|2|3|$4|5|6|@8|9]]|7|$4|5|6|@A|B]]]]]'
|
||||
)
|
||||
).toEqual(geoJSON);
|
||||
});
|
||||
|
||||
test('Errors when not enough parts exist', () => {
|
||||
expect(() => decompress('a|b^1K6^')).toThrowError();
|
||||
});
|
||||
|
||||
@@ -171,11 +171,19 @@ export function decompress(input: string): unknown {
|
||||
const parts = input.split('^');
|
||||
if (parts.length !== 4) throw new Error(`Invalid input string given`);
|
||||
|
||||
const values: (string | number)[] = [
|
||||
...parts[0]!.split('|').map((part) => decode(part)),
|
||||
...parts[1]!.split('|').map((part) => to10(part)),
|
||||
...parts[2]!.split('|').map((part) => parseFloat(part)),
|
||||
];
|
||||
const values: (string | number)[] = [];
|
||||
|
||||
if (parts[0]) {
|
||||
values.push(...parts[0]!.split('|').map((part) => decode(part)));
|
||||
}
|
||||
|
||||
if (parts[1]) {
|
||||
values.push(...parts[1]!.split('|').map((part) => to10(part)));
|
||||
}
|
||||
|
||||
if (parts[2]) {
|
||||
values.push(...parts[2]!.split('|').map((part) => parseFloat(part)));
|
||||
}
|
||||
|
||||
let num36Buffer = '';
|
||||
const tokens: (string | number)[] = [];
|
||||
|
||||
Reference in New Issue
Block a user