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

Negative indentLevel throwing RangeError when prettyPrinting #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Negative indentLevel throwing RangeError when prettyPrinting #73

wants to merge 1 commit into from

Conversation

lathonez
Copy link

Believe it or not this is from a real world example. Found on http://pro.jsonlint.com and followed back here.

Simplest replication I can find:

air:~$ cat bad.json
{
        "key": "value"
}
}
}
air:~$ jsonlint -p bad.json
[RangeError: Invalid array length]
undefined

Without pretty printing it works fine as the formatter isn't used:

air:~$ jsonlint bad.json
[Error: Parse error on line 3:
...  "key": "value"}}}
--------------------^
Expecting 'EOF', got '}']

My fix is to force the count value to zero inside jsl.format.repeat if it happens to be negative, which gives the following output:

air:~$ jsonlint -p bad.json
[Error: Parse error on line 3:
...  "key": "value"}}}
--------------------^
Expecting 'EOF', got '}']
{
  "key": "value"
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant