Skip to content

Commit

Permalink
Detect invalid JSON on test page
Browse files Browse the repository at this point in the history
  • Loading branch information
iradul committed Dec 4, 2018
1 parent 9bb4f1b commit 3b25a95
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 76 deletions.
153 changes: 78 additions & 75 deletions k2ws/static.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion k2ws/static/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,22 @@
}
setTimeout($f_statsTick, 1000);

function $$isJSON(msg) {
if (msg.length === 0 || msg[0] !== '{' && msg[0] !== '[') return false;
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}

function $$evalFilter(msg) {
if ($$flags.filterEnabled) {
try {
if (!$$isJSON(msg) && !/^[0-9]+(\.[0-9]*)?$/.test(msg)) {
msg = '`' + msg.replace(/`/g, '\\`') + '`';
}
msg = eval('var m=' + msg + ';\n' + $$el.filterEditor.getValue());
if (msg && typeof (msg) === 'object') {
msg = JSON.stringify(msg, null, 4);
Expand Down Expand Up @@ -255,7 +268,7 @@
} catch(e) {
isString = true;
}
$$flags.message += splitter + (isString ? '"' + msg + '"' : msg);
$$flags.message += splitter + (isString ? '"' + msg.replace(/"/g, '\\"') + '"' : msg);
$$flags.stackedMessages++;
} else {
$$flags.message = msg;
Expand Down

0 comments on commit 3b25a95

Please sign in to comment.