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

Fix OOM when parsing bare hexadecimal literal. #229

Merged
merged 2 commits into from Apr 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/util.js
Expand Up @@ -2,11 +2,11 @@ const unicode = require('../lib/unicode')

module.exports = {
isSpaceSeparator (c) {
return unicode.Space_Separator.test(c)
return typeof c === 'string' && unicode.Space_Separator.test(c)
},

isIdStartChar (c) {
return (
return typeof c === 'string' && (
(c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c === '$') || (c === '_') ||
Expand All @@ -15,7 +15,7 @@ module.exports = {
},

isIdContinueChar (c) {
return (
return typeof c === 'string' && (
(c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
Expand All @@ -26,10 +26,10 @@ module.exports = {
},

isDigit (c) {
return /[0-9]/.test(c)
return typeof c === 'string' && /[0-9]/.test(c)
},

isHexDigit (c) {
return /[0-9A-Fa-f]/.test(c)
return typeof c === 'string' && /[0-9A-Fa-f]/.test(c)
},
}
24 changes: 24 additions & 0 deletions test/parse.js
Expand Up @@ -178,6 +178,30 @@ t.test('parse(text)', t => {
'parses signed NaN'
)

t.strictSame(
JSON5.parse('1'),
1,
'parses 1'
)

t.strictSame(
JSON5.parse('+1.23e100'),
1.23e100,
'parses +1.23e100'
)

t.strictSame(
JSON5.parse('0x1'),
0x1,
'parses bare hexadecimal number'
)

t.strictSame(
JSON5.parse('-0x0123456789abcdefABCDEF'),
-0x0123456789abcdefABCDEF,
'parses bare long hexadecimal number'
)

t.end()
})

Expand Down