Skip to content

Commit e656622

Browse files
author
Túlio Ornelas
committed
add a better check for empty node
1 parent 05f7c32 commit e656622

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

extension/src/json-viewer/check-if-json.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ function allTextNodes(nodes) {
99
function getPreWithSource() {
1010
var childNodes = document.body.childNodes;
1111

12-
if (childNodes.length > 1 && childNodes[0].nodeName === "#text"){
1312
if (childNodes.length > 1 && allTextNodes(childNodes)) {
1413
if (process.env.NODE_ENV === 'development') {
1514
console.debug("[JSONViewer] Loaded from a multiple text nodes, normalizing");
@@ -27,7 +26,7 @@ function getPreWithSource() {
2726
return childNode;
2827

2928
// if Content-Type is text/html
30-
} else if (nodeName === "#text" && !/^\s+$/g.test(textContent)) {
29+
} else if (nodeName === "#text" && textContent.trim().length > 0) {
3130
if (process.env.NODE_ENV === 'development') {
3231
console.debug("[JSONViewer] Loaded from a text node, this might have returned content-type: text/html");
3332
}

0 commit comments

Comments
 (0)