js-beautify icon indicating copy to clipboard operation
js-beautify copied to clipboard

syntax error in beautified code when using "unescape-strings" (Unescape printable chars encoded as \xNN or \uNNNN)

Open ObjectAscended opened this issue 1 year ago • 0 comments

Description

when using the "unescape-strings" (Unescape printable chars encoded as \xNN or \uNNNN) feature, some encoded characters cause a new line to be created, which is a syntax error in the code

Input

The code looked like this before beautification:

let encodedString = '\u2028';
let encodedString2 = '\u2029';

console.log(encodedString, encodedString2);

Expected Output

The code should have looked like this after beautification:

let encodedString = '
';
let encodedString2 = '
';

console.log(encodedString, encodedString2);

Actual Output

The code actually looked like this after beautification:

let encodedString = '
';
let encodedString2 = '
';

console.log(encodedString, encodedString2);

Steps to Reproduce

  1. go to https://beautifier.io/
  2. enable "Unescape printable chars encoded as \xNN or \uNNNN"
  3. paste in code below:
let encodedString = '\u2028';
let encodedString2 = '\u2029';

console.log(encodedString, encodedString2);
  1. error in beautified code

Environment

OS: Web

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": "end-expand",
  "space_before_conditional": false,
  "unescape_strings": true,
  "jslint_happy": false,
  "end_with_newline": false,
  "wrap_line_length": "0",
  "indent_inner_html": false,
  "comma_first": false,
  "e4x": false,
  "indent_empty_lines": false
}

ObjectAscended avatar Apr 27 '24 01:04 ObjectAscended