Skip to content

Commit

Permalink
fix(frontend): allow "constructor" property in response data (apache#…
Browse files Browse the repository at this point in the history
  • Loading branch information
SpencerTorres authored and EnxDev committed Apr 12, 2024
1 parent ecf6f6d commit 886c9f9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
import JSONbig from 'json-bigint';
import _JSONbig from 'json-bigint';
import { cloneDeepWith } from 'lodash';

import { ParseMethod, TextResponse, JsonResponse } from '../types';

const JSONbig = _JSONbig({
constructorAction: 'preserve',
});

export default async function parseResponse<T extends ParseMethod = 'json'>(
apiPromise: Promise<Response>,
parseMethod?: T,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,12 @@ describe('parseResponse()', () => {

it('resolves to big number value if `parseMethod=json-bigint`', async () => {
const mockBigIntUrl = '/mock/get/bigInt';
const mockGetBigIntPayload =
'{ "value": 9223372036854775807, "minus": { "value": -483729382918228373892, "str": "something" }, "number": 1234, "floatValue": { "plus": 0.3452211361231223, "minus": -0.3452211361231223 } }';
const mockGetBigIntPayload = `{
"value": 9223372036854775807, "minus": { "value": -483729382918228373892, "str": "something" },
"number": 1234, "floatValue": { "plus": 0.3452211361231223, "minus": -0.3452211361231223 },
"string.constructor": "data.constructor",
"constructor": "constructor"
}`;
fetchMock.get(mockBigIntUrl, mockGetBigIntPayload);
const responseBigNumber = await parseResponse(
callApi({ url: mockBigIntUrl, method: 'GET' }),
Expand All @@ -167,6 +171,10 @@ describe('parseResponse()', () => {
expect(Math.abs(responseBigNumber.json.floatValue.minus)).toEqual(
responseBigNumber.json.floatValue.plus,
);
expect(responseBigNumber.json['string.constructor']).toEqual(
'data.constructor',
);
expect(responseBigNumber.json.constructor).toEqual('constructor');
});

it('rejects if request.ok=false', async () => {
Expand Down
7 changes: 6 additions & 1 deletion superset-frontend/src/components/FilterableTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
import JSONbig from 'json-bigint';
import _JSONbig from 'json-bigint';
import React, { useEffect, useRef, useState, useMemo } from 'react';
import { getMultipleTextDimensions, styled } from '@superset-ui/core';
import { useDebounceValue } from 'src/hooks/useDebounceValue';
import { useCellContentParser } from './useCellContentParser';
import { renderResultCell } from './utils';
import { Table, TableSize } from '../Table';

const JSONbig = _JSONbig({
storeAsString: true,
constructorAction: 'preserve',
});

const SCROLL_BAR_HEIGHT = 15;
// This regex handles all possible number formats in javascript, including ints, floats,
// exponential notation, NaN, and Infinity.
Expand Down

0 comments on commit 886c9f9

Please sign in to comment.