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

Bug: Breaks when the source code it found an unclosed multiline comment. #996

Closed
ajinabraham opened this issue Aug 11, 2016 · 2 comments
Closed

Comments

@ajinabraham
Copy link

ajinabraham commented Aug 11, 2016

>>> x = u"\t\t\t// with unwanted files\n\t\t\tfs.unlink(tmp_path, function() {\n\t\t\t\tif (err) {\n\t\t\t\t\tthrow err\n\t\t\t\t}\n\t\t\t\tres.send('File uploaded to: ' + target_path + ' - ' + req.files.thumbnail.size + ' bytes')\n\t\t\t});\n\t\t});\n\t});\n\t*/"
>>> x
u"\t\t\t// with unwanted files\n\t\t\tfs.unlink(tmp_path, function() {\n\t\t\t\tif (err) {\n\t\t\t\t\tthrow err\n\t\t\t\t}\n\t\t\t\tres.send('File uploaded to: ' + target_path + ' - ' + req.files.thumbnail.size + ' bytes')\n\t\t\t});\n\t\t});\n\t});\n\t*/"
>>> len(x)
214
>>> import jsbeautifier
>>> jsbeautifier.beautify(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ajin/Code/x/venv/lib/python2.7/site-packages/jsbeautifier/__init__.py", line 246, in beautify
    return b.beautify(string, opts)
  File "/Users/ajin/Code/x/venv/lib/python2.7/site-packages/jsbeautifier/__init__.py", line 429, in beautify
    self.tokens = Tokenizer(input, self.opts, self.indent_string).tokenize()
  File "/Users/ajin/Code/x/venv/lib/python2.7/site-packages/jsbeautifier/__init__.py", line 1584, in tokenize
    token_values = self.__tokenize_next()
  File "/Users/ajin/Code/x/venv/lib/python2.7/site-packages/jsbeautifier/__init__.py", line 1748, in __tokenize_next
    if self.input[self.parser_pos] == '*': # peek /* .. */ comment
IndexError: string index out of range
@ajinabraham ajinabraham changed the title Bug: Breaks when the source code is partially invalid Bug: Breaks when the source code it found an unclosed multiline comment. Aug 11, 2016
@ajinabraham
Copy link
Author

Smaller PoC:

>>> x = "sd=1;*/"                                                                                                                                                                  >>> jsbeautifier.beautify(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ajin/Code/NodeJSCloudScan/venv/lib/python2.7/site-packages/jsbeautifier/__init__.py", line 246, in beautify
    return b.beautify(string, opts)
  File "/Users/ajin/Code/NodeJSCloudScan/venv/lib/python2.7/site-packages/jsbeautifier/__init__.py", line 429, in beautify
    self.tokens = Tokenizer(input, self.opts, self.indent_string).tokenize()
  File "/Users/ajin/Code/NodeJSCloudScan/venv/lib/python2.7/site-packages/jsbeautifier/__init__.py", line 1584, in tokenize
    token_values = self.__tokenize_next()
  File "/Users/ajin/Code/NodeJSCloudScan/venv/lib/python2.7/site-packages/jsbeautifier/__init__.py", line 1748, in __tokenize_next
    if self.input[self.parser_pos] == '*': # peek /* .. */ comment
IndexError: string index out of range

@ajinabraham
Copy link
Author

The ideal way is to gracefully skip line

@bitwiseman bitwiseman added this to the v1.6.4 milestone Aug 11, 2016
bitwiseman added a commit that referenced this issue Aug 26, 2016
bitwiseman added a commit to bitwiseman/js-beautify that referenced this issue Aug 27, 2016
bitwiseman added a commit to bitwiseman/js-beautify that referenced this issue Aug 27, 2016
bitwiseman added a commit to bitwiseman/js-beautify that referenced this issue Aug 28, 2016
bitwiseman added a commit to bitwiseman/js-beautify that referenced this issue Aug 28, 2016
bitwiseman added a commit to bitwiseman/js-beautify that referenced this issue Aug 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants