question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

please respect unicode strings you are given

See original GitHub issue

esprima.parse('a = "привет"') clearly preserves unicode strings in the format supplied

{ type: 'Program',
  body: 
   [ { type: 'ExpressionStatement',
       expression: 
        { type: 'AssignmentExpression',
          operator: '=',
          left: { type: 'Identifier', name: 'a' },
          right: { type: 'Literal', value: 'привет', raw: '"привет"' } } } ] }

esgen(esprima.parse('a = "привет"')) clearly does not

a = '\u043F\u0440\u0438\u0432\u0435\u0442';

Technically these js-strings are equivalent, but why forego readability?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
michaelficarracommented, Apr 27, 2015

@vkz

What does render safely mean?

We can’t have " in "-delimited strings. We can’t have a carriage return or a paragraph separator. To avoid these characters, we can just Unicode escape everything. It’s the same string. If you really want to avoid Unicode escapes, use {format: {escapeless: true}} as your escodegen options. But the only way to use the same escapes that you used in your original code is to use the {verbatim: "raw"} option.

0reactions
vkzcommented, Apr 28, 2015
var esprima = require("esprima"),
    esgen = require("escodegen").generate,
    uglify = require("uglify-js");

var exhibit1 = '"\0 \x00 \u0000 0 \x30 \u0030"',
    ast1 = esprima.parse(exhibit1),
    exhibit2 = "'привет'",
    ast2 = esprima.parse(exhibit2);

esgen(ast1);
uglify.AST_Node.from_mozilla_ast(ast1).print_to_string();

esgen(ast2);
uglify.AST_Node.from_mozilla_ast(ast2).print_to_string();

every time uglify-js does this horribly unsafe thing a puppy dies.

Having lost several hours of my life debugging this safe behaviour I feel some friendly trolling is warranted here. There’ll be many a poor sobs down the road tripping over this, I’m sure.

NB: Esprima and Escodegen have saved me countless hours, I use them daily and I am absolutely grateful to their authors and maintainers for keeping them open source and providing support.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to solve unicode encoding issues - Invivoo
In ths new article, our expert will explain you how to solve unicode encoding issues. If you have any question, don't hesite to...
Read more >
python3 pySerial TypeError: unicode strings are not supported ...
Encode your data which you are writing to serial,in your case "serialcmd" to bytes.try the following : ser.write(serialcmd.encode()).
Read more >
Unicode strings - Rosetta Code
For handling multiple languages, Unicode is your best friend. Task. Unicode strings. You are encouraged to solve this task according to the task ......
Read more >
UAX #15: Unicode Normalization Forms
This annex describes normalization forms for Unicode text. When implementations keep strings in a normalized form, they can be assured that equivalent ...
Read more >
Typing Unicode string - NI Community - National Instruments
Hi All, I am trying to type Unicode strings in LabVIEW 2015. ... Similarly, if you are given a Unicode String, you can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found