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

Invalid prettification of object with unicode escape character as object key #2159

Closed
leumasme opened this issue Jun 21, 2023 · 6 comments
Closed

Comments

@leumasme
Copy link

Description

For the below seen kind of Unicode Literal as Key, js-beautify breaks the code.
The resulting code creates a SyntaxError: Invalid or unexpected token
I also only today learned that the input is valid syntax. It's apparently equivalent to {"𝒶": "ascr"} (note that "𝒶" != "a")

Input

The code looked like this before beautification:

{\u{1d4b6}:"ascr"}

Expected Output

The code should have looked like this after beautification:

{
    \u{1d4b6}: "ascr"
}

or

{
  "\u{1d4b6}": "ascr"
}

or

{
  "𝒶": "ascr"
}

Actual Output

The code actually looked like this after beautification:

{
    \
    u {
        1 d4b6
    }: "ascr"
}

(This is invalid js which fails to execute)

Steps to Reproduce

Simply paste input into js-beautify with default settings (web/npm)

Environment

Tested both in browser via https://beautifier.io/
and using the npm package js-beautify@1.14.8 on Windows 10.

Settings

Example:

{
  "indent_size": "4",
  "indent_char": " ",
  "max_preserve_newlines": "5",
  "preserve_newlines": true,
  "keep_array_indentation": false,
  "break_chained_methods": false,
  "indent_scripts": "normal",
  "brace_style": "collapse",
  "space_before_conditional": true,
  "unescape_strings": false,
  "jslint_happy": false,
  "end_with_newline": false,
  "wrap_line_length": "0",
  "indent_inner_html": false,
  "comma_first": false,
  "e4x": false,
  "indent_empty_lines": false
}
@hilalsidhic
Copy link

Hi can someone assign this to me

@bitwiseman
Copy link
Member

@hilalsidhic Done.

@Himang02
Copy link

Is the issue Open? I want to contribute.

@bitwiseman
Copy link
Member

It is open. @hilalsidhic doesn't seem to be working on it. Go ahead.

@Chaitanyaprasad60
Copy link

Can you assign me this?

@Bharrguv
Copy link

Is this still open ? If yes I am willing to contribute @bitwiseman

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

6 participants