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

Javascript multiline comments duplicates #1663

Closed
D-AIRY opened this issue Apr 19, 2019 · 4 comments
Closed

Javascript multiline comments duplicates #1663

D-AIRY opened this issue Apr 19, 2019 · 4 comments

Comments

@D-AIRY
Copy link

D-AIRY commented Apr 19, 2019

Description

Javascript multiline comments duplicates

Input

The code looked like this before beautification:

	/* comment
	
	*/

Expected Output

The code should have looked like this after beautification:

	/* comment
	
	*/

Actual Output

The code actually looked like this after beautification:

	/* comment
	/* comment
	
	*/
	*/

Steps to Reproduce

  1. go to https://beautifier.io/
  2. use following code with default options:
\t/* comment\n
\t\n
\t*/\n

Environment

OS: windows 7

Settings

Example:

{
    "indent_size": 4,
    "indent_char": " ",
    "indent_level": 0,
    "indent_with_tabs": true,
    "preserve_newlines": true,
    "max_preserve_newlines": 10,
    "jslint_happy": false,
    "space_after_anon_function": false,
    "brace_style": "collapse,preserve-inline",
    "keep_array_indentation": false,
    "keep_function_indentation": false,
    "space_before_conditional": true,
    "break_chained_methods": false,
    "eval_code": false,
    "unescape_strings": false,
    "wrap_line_length": 0
}
@bitwiseman
Copy link
Member

@D-AIRY
I can't reproduce this issue. Is the settings text above what was shown on the site?
What browser are you using?

@D-AIRY
Copy link
Author

D-AIRY commented Apr 19, 2019

Try this file:
bug.txt
Ensure you have tab charated in lines 1-3 and empty line 4
Also reproducible with default settings.
Tested in latest firefox and ios safari

@bitwiseman
Copy link
Member

@D-AIRY
wow. Great bug. Thanks!

@bitwiseman
Copy link
Member

NOTES:

Also happens with:

 /* one space before each line
 
 */

The problem is that blank line is being turn into an empty string and passed to print_token.

https://github.com/beautify-web/js-beautify/blob/d88c6a64620c3e795ff34344029e00941f1e297a/js/src/javascript/beautifier.js#L1372

In there we have this line:

https://github.com/beautify-web/js-beautify/blob/d88c6a64620c3e795ff34344029e00941f1e297a/js/src/javascript/beautifier.js#L429

Which doesn't distinguish between empty string and null, but it should.

This hasn't been run into more because usually blank lines get turned into empty lines.

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