Skip to content

Commit 2290024

Browse files
authored
Merge pull request #324 from vfabioux/develop
fix removeComments from parseJson
2 parents 50dcae3 + 5891a43 commit 2290024

File tree

4 files changed

+23
-37
lines changed

4 files changed

+23
-37
lines changed

package-lock.json

Lines changed: 17 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"pinia-plugin-persistedstate": "^4.5.0",
4242
"pretty-bytes": "^7.1.0",
4343
"quasar": "^2.18.5",
44+
"strip-json-comments": "^5.0.3",
4445
"ua-parser-js": "^2.0.6",
4546
"uuid": "^13.0.0",
4647
"vue": "^3.5.22",
@@ -71,4 +72,4 @@
7172
"vitest": "^3.2.4",
7273
"vue-tsc": "^3.1.1"
7374
}
74-
}
75+
}

src/composables/components/rest/RestQueryForm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import stripJsonComments from 'strip-json-comments'
12
import { computed, ref, toRaw, watch, nextTick } from 'vue'
23
import { clusterAuthHeader } from '../../../helpers/elasticsearchAdapter.ts'
34
import { REQUEST_DEFAULT_HEADERS } from '../../../consts'
45
import { useConnectionStore } from '../../../store/connection'
56
import { useSnackbar } from '../../Snackbar'
67
import { useIdbStore } from '../../../db/Idb'
7-
import { removeComments } from '../../../helpers/json/parse'
88
import { fetchMethod } from '../../../helpers/fetch'
99
import { IdbRestQueryTab, IdbRestQueryTabRequest } from '../../../db/types.ts'
1010
import { debounce } from '../../../helpers/debounce.ts'
@@ -39,7 +39,7 @@ export const useRestQueryForm = (props: RestQueryFormProps, emit: any) => {
3939

4040
const options: RestFetchOptions = {
4141
method: props.tab.request.method,
42-
body: ['GET', 'HEAD'].includes(props.tab.request.method) ? null : removeComments(props.tab.request.body),
42+
body: ['GET', 'HEAD'].includes(props.tab.request.method) ? null : stripJsonComments(props.tab.request.body),
4343
headers: Object.assign({}, REQUEST_DEFAULT_HEADERS)
4444
}
4545

src/helpers/json/parse.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1+
import stripJsonComments from 'strip-json-comments'
12
import { bigint } from './jsonBigint.ts'
23

3-
export const removeComments = (str: string): string => {
4-
return str.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m, g) => (g ? '' : m))
5-
}
6-
74
export const parseJson = (jsonString: string): any => {
8-
const clean = removeComments(jsonString)
5+
const clean = stripJsonComments(jsonString)
96
return bigint.parse(clean)
107
}

0 commit comments

Comments
 (0)