Skip to content

Commit

Permalink
fix: json string validation
Browse files Browse the repository at this point in the history
Signed-off-by: Sai Ranjit Tummalapalli <[email protected]>
  • Loading branch information
sairanjit committed Apr 18, 2024
1 parent bb51cab commit 0bd8ace
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions app/components/record/RecordField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ export const AttributeValue: React.FC<AttributeValueParams> = ({ field, style, s
)
}

const isJsonString = (value: string) => {
if (typeof value !== 'string' || Number(value)) {
return false
}
try {
JSON.parse(value)
} catch (e) {
return false
}
return true
}

const RecordField: React.FC<RecordFieldProps> = ({
field,
hideFieldValue = false,
Expand Down Expand Up @@ -92,19 +104,7 @@ const RecordField: React.FC<RecordFieldProps> = ({
},
})

const isJSON = (text: string) => {
if (typeof text !== 'string') {
return false
}
try {
JSON.parse(text)
return true
} catch (error) {
return false
}
}

if (isJSON(field?.value)) {
if (isJsonString(field?.value)) {
return
}

Expand Down

0 comments on commit 0bd8ace

Please sign in to comment.