Revert "Frontend: Use safe stringifier in parseBody" (#90522)

Revert "Frontend: Use safe stringifier in parseBody (#90047)"

This reverts commit 434f386982.
pull/90526/head
Ivan Ortega Alba 10 months ago committed by GitHub
parent 8f376a302b
commit 3559c5c297
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      packages/grafana-data/src/index.ts
  2. 19
      packages/grafana-data/src/utils/object.ts
  3. 4
      public/app/core/utils/fetch.ts

@ -246,7 +246,7 @@ export {
} from './utils/csv'; } from './utils/csv';
export { parseLabels, findCommonLabels, findUniqueLabels, matchAllLabels, formatLabels } from './utils/labels'; export { parseLabels, findCommonLabels, findUniqueLabels, matchAllLabels, formatLabels } from './utils/labels';
export { roundDecimals, guessDecimals } from './utils/numbers'; export { roundDecimals, guessDecimals } from './utils/numbers';
export { objRemoveUndefined, isEmptyObject, safeStringifyValue } from './utils/object'; export { objRemoveUndefined, isEmptyObject } from './utils/object';
export { classicColors } from './utils/namedColorsPalette'; export { classicColors } from './utils/namedColorsPalette';
export { getSeriesTimeStep, hasMsResolution } from './utils/series'; export { getSeriesTimeStep, hasMsResolution } from './utils/series';
export { BinaryOperationID, type BinaryOperation, binaryOperators } from './utils/binaryOperators'; export { BinaryOperationID, type BinaryOperation, binaryOperators } from './utils/binaryOperators';

@ -10,22 +10,3 @@
export const isEmptyObject = (value: unknown): value is Record<string, never> => { export const isEmptyObject = (value: unknown): value is Record<string, never> => {
return typeof value === 'object' && value !== null && Object.keys(value).length === 0; return typeof value === 'object' && value !== null && Object.keys(value).length === 0;
}; };
/** Stringifies an object that may contain circular references */
export function safeStringifyValue(value: unknown) {
const getCircularReplacer = () => {
const seen = new WeakSet();
return (_: string, value: object | null) => {
if (typeof value === 'object' && value !== null) {
if (seen.has(value)) {
return;
}
seen.add(value);
}
return value;
};
};
return JSON.stringify(value, getCircularReplacer());
}

@ -1,6 +1,6 @@
import { omitBy } from 'lodash'; import { omitBy } from 'lodash';
import { deprecationWarning, safeStringifyValue } from '@grafana/data'; import { deprecationWarning } from '@grafana/data';
import { BackendSrvRequest } from '@grafana/runtime'; import { BackendSrvRequest } from '@grafana/runtime';
export const parseInitFromOptions = (options: BackendSrvRequest): RequestInit => { export const parseInitFromOptions = (options: BackendSrvRequest): RequestInit => {
@ -93,7 +93,7 @@ export const parseBody = (options: BackendSrvRequest, isAppJson: boolean) => {
return options.data; return options.data;
} }
return isAppJson ? safeStringifyValue(options.data) : new URLSearchParams(options.data); return isAppJson ? JSON.stringify(options.data) : new URLSearchParams(options.data);
}; };
export async function parseResponseBody<T>( export async function parseResponseBody<T>(

Loading…
Cancel
Save