Deno: New prompt, alert and confirm methods get confused when escaping special characters [ã]

Created on 29 Oct 2020  Â·  6Comments  Â·  Source: denoland/deno

The new adition of prompt, alert and confirm methods are great news for all of us!! Glad to have those!

However, after the small #8146 issue, there is yet another unrelated problem with the new tools: special UTF-8 (maybe UTF-16?) characters (ãñõâêîôûü, for example):

image

It happens both on the alert/confirm/prompt message and on the return value. This does not happen on console.log, though. May be related or similar to old #5046.

deno 1.5.0
v8 8.7.220.3
typescript 4.0.3

bug cli windows 🗔

All 6 comments

May have something to do with this. But not sure.

Another example, this time with some kanji.

image

console.log(prompt('My prompt: 你好;').trim());

Latin example:

console.log(prompt('My prompt: ãõâêîôûüïáéíóúàèìòùç;').trim());

One more example:
When running the code below and inserting the characters 'a' and 'ã', one at a time, this is what we get:

const a = prompt('Insert your character');

console.log(`a===a => ${a === 'a'}`);  // When inserting the character 'a', returns true, as expected!
console.log(`ã===ã => ${a === 'ã'}`); // When inserting the character 'ã', returns false...

I found that Deno.stdout.writeSync(new TextEncoder().encode("ã")) causes the same problem (tested in powershell in windows).

スクリーンショット 2020-10-30 17 55 14

It seems that Deno.core.print can be a workaround.

Was looking at the rustyline crate and it seems to use utf16 for reading input: https://github.com/kkawakam/rustyline/blob/master/src/tty/windows.rs#L105

8199 fixes the output of non-ascii characters, but the problem in reading non-ascii chars from stdin (in windows) is still remaining. The above utf-16 decoding could be a solution.

Addition of utf-16 encoding is in progress at https://github.com/denoland/deno/pull/8108

@piscisaureus I don't know if we can call this issue fully fixed. The output part of it is solved, it seems, but the input part of it is still nor recognizing special UTF-16 characters.

For example, when running the code below and inserting the characters 'a' and 'ã', one at a time, this is what we get:

const a = prompt('Insert your character');

console.log(`a===a => ${a === 'a'}`);  // When inserting the character 'a', returns true, as expected!
console.log(`ã===ã => ${a === 'ã'}`); // When inserting the character 'ã', returns false, not what we expected.

Maybe we can open a new issue just for the input part, or reopen this one.

Edit: opened new issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ry picture ry  Â·  3Comments

doutchnugget picture doutchnugget  Â·  3Comments

sh7dm picture sh7dm  Â·  3Comments

watilde picture watilde  Â·  3Comments

xueqingxiao picture xueqingxiao  Â·  3Comments