8000 scripts: replace JSON.stringify with json-stable-stringify by oleggator · Pull Request #3701 · weaveworks/scope · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

scripts: replace JSON.stringify with json-stable-stringify #3701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import moment from 'moment';
import { connect } from 'react-redux';
import stableStringify from 'json-stable-stringify';

import NodeDetailsHealthItem from './node-details-health-item';
import CloudLink from '../cloud-link';
Expand Down Expand Up @@ -30,7 +31,7 @@ export function appendTime(url, time) {
return url;
}

return `${url.substr(0, pos + cloudLinkPathEnd.length)}${encodeURIComponent(JSON.stringify(payload) || '')}`;
return `${url.substr(0, pos + cloudLinkPathEnd.length)}${encodeURIComponent(stableStringify(payload) || '')}`;
}

if (url.indexOf('?') !== -1) {
Expand Down
3 changes: 2 additions & 1 deletion client/app/scripts/components/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import classNames from 'classnames';
import { debounce } from 'lodash';
import { Terminal as Term } from 'xterm';
import * as fit from 'xterm/lib/addons/fit/fit';
import stableStringify from 'json-stable-stringify';

import { closeTerminal } from '../actions/app-actions';
import { getPipeStatus } from '../actions/request-actions';
Expand Down Expand Up @@ -230,7 +231,7 @@ class Terminal extends React.Component {

handlePopoutTerminal(ev) {
ev.preventDefault();
const paramString = JSON.stringify(this.props);
const paramString = stableStringify(this.props);
this.props.dispatch(closeTerminal(this.getPipeId()));
this.setState({detached: true});

Expand Down
3 changes: 2 additions & 1 deletion client/app/scripts/components/zoomable-canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import classNames from 'classnames';
import { connect } from 'react-redux';
import { clamp, debounce, pick } from 'lodash';
import { fromJS } from 'immutable';
import stableStringify from 'json-stable-stringify';

import { drag } from 'd3-drag';
import { event as d3Event, select } from 'd3-selection';
Expand Down Expand Up @@ -275,7 +276,7 @@ function mapStateToProps(state, props) {
canvasMargins: canvasMarginsSelector(state),
forceRelayout: state.get('forceRelayout'),
height: canvasHeightSelector(state),
layoutId: JSON.stringify(activeTopologyZoomCacheKeyPathSelector(state)),
layoutId: stableStringify(activeTopologyZoomCacheKeyPathSelector(state)),
layoutLimits: props.limitsSelector(state),
layoutZoomState: props.zoomStateSelector(state),
width: canvasWidthSelector(state),
Expand Down
3 changes: 2 additions & 1 deletion client/app/scripts/selectors/zooming.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createSelector } from 'reselect';
import { Map as makeMap } from 'immutable';
import stableStringify from 'json-stable-stringify';

import { isGraphViewModeSelector, activeTopologyOptionsSelector } from './topology';

Expand All @@ -10,7 +11,7 @@ export const activeTopologyZoomCacheKeyPathSelector = createSelector(
state => state.get('topologyViewMode'),
state => state.get('currentTopologyId'),
state => state.get('pinnedMetricType'),
state => JSON.stringify(activeTopologyOptionsSelector(state)),
state => stableStringify(activeTopologyOptionsSelector(state)),
],
(isGraphViewMode, viewMode, topologyId, pinnedMetricType, topologyOptions) => (
isGraphViewMode
Expand Down
3 changes: 2 additions & 1 deletion client/app/scripts/utils/hash-utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {
isPlainObject, mapValues, isEmpty, omitBy
} from 'lodash';
import stableStringify from 'json-stable-stringify';


export function hashDifferenceDeep(A, B) {
// If the elements have exactly the same content, the difference is an empty object.
// This could fail if the objects are both hashes with different permutation of keys,
// but this case we handle below by digging in recursively.
if (JSON.stringify(A) === JSON.stringify(B)) return {};
if (stableStringify(A) === stableStringify(B)) return {};

// Otherwise, if either element is not a hash, always return the first element
// unchanged as this function only takes difference of hash objects.
Expand Down
3 changes: 2 additions & 1 deletion client/app/scripts/utils/storage-utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import debug from 'debug';
import stableStringify from 'json-stable-stringify';

const log = debug('scope:storage-utils');

Expand Down Expand Up @@ -62,7 +63,7 @@ export function storageGetObject(

export function storageSetObject(key, obj, storage = localSessionStorage) {
try {
return storageSet(key, JSON.stringify(obj), storage);
return storageSet(key, stableStringify(obj), storage);
} catch (e) {
log('Error encoding object for key', key);
}
Expand Down
3 changes: 2 additions & 1 deletion client/app/scripts/utils/topology-utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { endsWith } from 'lodash';
import { Set as makeSet, List as makeList, Map as makeMap } from 'immutable';
import stableStringify from 'json-stable-stringify';

import { isPausedSelector } from '../selectors/time-travel';
import { isResourceViewModeSelector } from '../selectors/topology';
Expand Down Expand Up @@ -44,7 +45,7 @@ export function buildTopologyCacheId(topologyId, topologyOptions) {
if (topologyId) {
id = topologyId;
if (topologyOptions) {
id += JSON.stringify(topologyOptions);
id += stableStringify(topologyOptions);
}
}
return id;
Expand Down
3 changes: 2 additions & 1 deletion client/app/scripts/utils/web-api-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import debug from 'debug';
import reqwest from 'reqwest';
import { defaults } from 'lodash';
import { Map as makeMap, List } from 'immutable';
import stableStringify from 'json-stable-stringify';

import {
receiveError,
Expand Down Expand Up @@ -226,7 +227,7 @@ export function doResizeTty(pipeId, control, cols, rows) {
+ `${encodeURIComponent(control.nodeId)}/${control.id}`;

return doRequest({
data: JSON.stringify({ height: rows.toString(), pipeID: pipeId, width: cols.toString() }),
data: stableStringify({ height: rows.toString(), pipeID: pipeId, width: cols.toString() }),
method: 'POST',
url,
})
Expand Down
0