Skip to content

Commit db162d8

Browse files
hiveerHiveerLi
and
HiveerLi
authored
Add safe JSON parsing utility to RepoTabs component (#1050)
* Draft MR * Add safe JSON parsing utility to RepoTabs component --------- Co-authored-by: HiveerLi <[email protected]>
1 parent 260d464 commit db162d8

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

frontend/src/components/shared/RepoTabs.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
:maxReplica="repoDetail.maxReplica"
242242
:minReplica="repoDetail.minReplica"
243243
:clusterId="repoDetail.clusterId"
244-
:variables="repoDetail.engineArgs ? JSON.parse(repoDetail.engineArgs) : {}"
244+
:variables="safeJsonParse(repoDetail.engineArgs) ? JSON.parse(repoDetail.engineArgs) : {}"
245245
/>
246246
</template>
247247
</tab-container>
@@ -277,6 +277,7 @@
277277
import { ref, computed, onMounted } from 'vue'
278278
import { ElMessage } from 'element-plus'
279279
import { useI18n } from 'vue-i18n'
280+
import { safeJsonParse } from '../../packs/utils'
280281
281282
const { t } = useI18n()
282283

frontend/src/packs/utils.js

+26
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,30 @@ export const ToUnauthorizedPage = () => {
5757
setTimeout(() => {
5858
location.href = '/errors/unauthorized'
5959
}, 300)
60+
}
61+
62+
export const randomUUID = () => {
63+
const hexDigits = '0123456789abcdef'
64+
let uuid = ''
65+
66+
for (let i = 0; i < 36; i++) {
67+
if (i === 8 || i === 13 || i === 18 || i === 23) {
68+
uuid += '-'
69+
} else if (i === 14) {
70+
uuid += '4'
71+
} else if (i === 19) {
72+
uuid += hexDigits[Math.floor(Math.random() * 4) + 8]
73+
} else {
74+
uuid += hexDigits[Math.floor(Math.random() * 16)]
75+
}
76+
}
77+
return uuid
78+
}
79+
80+
export const safeJsonParse = (str) => {
81+
try {
82+
return JSON.parse(str)
83+
} catch (e) {
84+
return null
85+
}
6086
}

0 commit comments

Comments
 (0)