Skip to content
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

Only JSON.parse JSON strings in tags/logs values #162

Merged
merged 1 commit into from
Dec 26, 2017
Merged
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
Expand Up @@ -19,12 +19,15 @@ import jsonMarkup from 'json-markup';

import './KeyValuesTable.css';

function parseOrPass(value) {
function parseIfJson(value) {
try {
return JSON.parse(value);
} catch (_) {
return value;
}
const data = JSON.parse(value);
if (data && typeof data === 'object') {
return data;
}
// eslint-disable-next-line no-empty
} catch (_) {}
return value;
}

type KeyValuesTableProps = {
Expand All @@ -40,7 +43,7 @@ export default function KeyValuesTable(props: KeyValuesTableProps) {
{data.map((row, i) => {
const jsonTable = (
// eslint-disable-next-line react/no-danger
<div dangerouslySetInnerHTML={{ __html: jsonMarkup(parseOrPass(row.value)) }} />
<div dangerouslySetInnerHTML={{ __html: jsonMarkup(parseIfJson(row.value)) }} />
);
return (
// `i` is necessary in the key because row.key can repeat
Expand Down