diff --git a/packages/bruno-app/package.json b/packages/bruno-app/package.json index b9c86fbb..07ede99d 100644 --- a/packages/bruno-app/package.json +++ b/packages/bruno-app/package.json @@ -50,7 +50,6 @@ "react-redux": "^7.2.6", "react-tooltip": "^5.5.2", "sass": "^1.46.0", - "split-on-first": "^3.0.0", "styled-components": "^5.3.3", "tailwindcss": "^2.2.19", "yup": "^0.32.11" diff --git a/packages/bruno-app/src/components/SingleLineEditor/index.js b/packages/bruno-app/src/components/SingleLineEditor/index.js index ad60a168..e49f0c61 100644 --- a/packages/bruno-app/src/components/SingleLineEditor/index.js +++ b/packages/bruno-app/src/components/SingleLineEditor/index.js @@ -102,7 +102,7 @@ class SingleLineEditor extends Component { } if (this.props.value !== prevProps.value && this.props.value !== this.cachedValue && this.editor) { this.cachedValue = this.props.value; - this.editor.setValue(this.props.value); + this.editor.setValue(this.props.value || ''); } this.ignoreChangeEvent = false; } diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js index 46606253..56a03b72 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js @@ -8,7 +8,7 @@ import filter from 'lodash/filter'; import each from 'lodash/each'; import cloneDeep from 'lodash/cloneDeep'; import { createSlice } from '@reduxjs/toolkit'; -import splitOnFirst from 'split-on-first'; +import { splitOnFirst } from 'utils/url'; import { findCollectionByUid, findCollectionByPathname, diff --git a/packages/bruno-app/src/utils/url/index.js b/packages/bruno-app/src/utils/url/index.js index d8166f52..41ae8aa7 100644 --- a/packages/bruno-app/src/utils/url/index.js +++ b/packages/bruno-app/src/utils/url/index.js @@ -40,3 +40,16 @@ export const stringifyQueryParams = (params) => { return queryString.join('&'); }; + +export const splitOnFirst = (str, char) => { + if(!str || !str.length) { + return [str]; + } + + let index = str.indexOf(char); + if (index === -1) { + return [str]; + } + + return [str.slice(0, index), str.slice(index + 1)]; +}; diff --git a/packages/bruno-app/src/utils/url/index.spec.js b/packages/bruno-app/src/utils/url/index.spec.js index 5dda69e4..67e32093 100644 --- a/packages/bruno-app/src/utils/url/index.spec.js +++ b/packages/bruno-app/src/utils/url/index.spec.js @@ -1,4 +1,4 @@ -import { parseQueryParams } from './index'; +import { parseQueryParams, splitOnFirst } from './index'; describe('Url Utils - parseQueryParams', () => { it('should parse query - case 1', () => { @@ -41,3 +41,30 @@ describe('Url Utils - parseQueryParams', () => { expect(params).toEqual([{name: 'a', value: '1'}, {name: 'b', value: '2'}]); }); }); + +describe('Url Utils - splitOnFirst', () => { + it('should split on first - case 1', () => { + const params = splitOnFirst("a", "="); + expect(params).toEqual(['a']); + }); + + it('should split on first - case 2', () => { + const params = splitOnFirst("a=", "="); + expect(params).toEqual(['a', '']); + }); + + it('should split on first - case 3', () => { + const params = splitOnFirst("a=1", "="); + expect(params).toEqual(['a', '1']); + }); + + it('should split on first - case 4', () => { + const params = splitOnFirst("a=1&b=2", "="); + expect(params).toEqual(['a', '1&b=2']); + }); + + it('should split on first - case 5', () => { + const params = splitOnFirst("a=1&b=2", "&"); + expect(params).toEqual(['a=1', 'b=2']); + }); +});