Skip to content

Commit

Permalink
Only JSON.parse JSON strings in tags/logs values (jaegertracing#162)
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Farro <joef@uber.com>
Signed-off-by: vvvprabhakar <vvvprabhakar@gmail.com>
  • Loading branch information
tiffon committed Dec 26, 2017
1 parent 36a075a commit a6e437a
Showing 1 changed file with 9 additions and 6 deletions.
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

0 comments on commit a6e437a

Please sign in to comment.