<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const msg = prompt();
console.log(msg);"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">msg</span> <span class="pl-c1">=</span> <span class="pl-en">prompt</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">msg</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Then enter <code class="notranslate">你好</code>, it outputs <code class="notranslate">�</code>.<br>
It looks like we should reconsider the implementation of <code class="notranslate">readline</code></p>
<p dir="auto"></p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/denoland/deno/blob/d40b0711a786d04b5e6321ae9bbf73c11220e865/cli/rt/41_prompt.js#L48-L73">deno/cli/rt/41_prompt.js</a>
    </p>
    <p class="mb-0 color-fg-muted">
        Lines 48 to 73
      in
      <a data-pjax="true" class="commit-tease-sha" href="/denoland/deno/commit/d40b0711a786d04b5e6321ae9bbf73c11220e865">d40b071</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L48" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="48"></td>
          <td id="LC48" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">function</span> <span class="pl-en">readLineFromStdinSync</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L49" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="49"></td>
          <td id="LC49" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">const</span> <span class="pl-s1">c</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">Uint8Array</span><span class="pl-kos">(</span><span class="pl-c1">1</span><span class="pl-kos">)</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L50" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="50"></td>
          <td id="LC50" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">const</span> <span class="pl-s1">buf</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L51" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="51"></td>
          <td id="LC51" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">  </td>
        </tr>

        <tr class="border-0">
          <td id="L52" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="52"></td>
          <td id="LC52" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">while</span> <span class="pl-kos">(</span><span class="pl-c1">true</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L53" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="53"></td>
          <td id="LC53" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-k">const</span> <span class="pl-s1">n</span> <span class="pl-c1">=</span> <span class="pl-s1">stdin</span><span class="pl-kos">.</span><span class="pl-en">readSync</span><span class="pl-kos">(</span><span class="pl-s1">c</span><span class="pl-kos">)</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L54" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="54"></td>
          <td id="LC54" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">n</span> <span class="pl-c1">===</span> <span class="pl-c1">null</span> <span class="pl-c1">||</span> <span class="pl-s1">n</span> <span class="pl-c1">===</span> <span class="pl-c1">0</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L55" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="55"></td>
          <td id="LC55" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">       <span class="pl-k">break</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L56" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="56"></td>
          <td id="LC56" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-kos">}</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L57" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="57"></td>
          <td id="LC57" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">c</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span> <span class="pl-c1">===</span> <span class="pl-c1">CR</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L58" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="58"></td>
          <td id="LC58" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">       <span class="pl-k">const</span> <span class="pl-s1">n</span> <span class="pl-c1">=</span> <span class="pl-s1">stdin</span><span class="pl-kos">.</span><span class="pl-en">readSync</span><span class="pl-kos">(</span><span class="pl-s1">c</span><span class="pl-kos">)</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L59" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="59"></td>
          <td id="LC59" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">       <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">c</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span> <span class="pl-c1">===</span> <span class="pl-c1">LF</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L60" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="60"></td>
          <td id="LC60" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">         <span class="pl-k">break</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L61" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="61"></td>
          <td id="LC61" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">       <span class="pl-kos">}</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L62" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="62"></td>
          <td id="LC62" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">       <span class="pl-s1">buf</span><span class="pl-kos">.</span><span class="pl-en">push</span><span class="pl-kos">(</span><span class="pl-c1">CR</span><span class="pl-kos">)</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L63" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="63"></td>
          <td id="LC63" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">       <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">n</span> <span class="pl-c1">===</span> <span class="pl-c1">null</span> <span class="pl-c1">||</span> <span class="pl-s1">n</span> <span class="pl-c1">===</span> <span class="pl-c1">0</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L64" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="64"></td>
          <td id="LC64" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">         <span class="pl-k">break</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L65" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="65"></td>
          <td id="LC65" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">       <span class="pl-kos">}</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L66" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="66"></td>
          <td id="LC66" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-kos">}</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L67" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="67"></td>
          <td id="LC67" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">c</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span> <span class="pl-c1">===</span> <span class="pl-c1">LF</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L68" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="68"></td>
          <td id="LC68" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">       <span class="pl-k">break</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L69" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="69"></td>
          <td id="LC69" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-kos">}</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L70" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="70"></td>
          <td id="LC70" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">     <span class="pl-s1">buf</span><span class="pl-kos">.</span><span class="pl-en">push</span><span class="pl-kos">(</span><span class="pl-s1">c</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L71" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="71"></td>
          <td id="LC71" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-kos">}</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L72" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="72"></td>
          <td id="LC72" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line">   <span class="pl-k">return</span> <span class="pl-s1">decoder</span><span class="pl-kos">.</span><span class="pl-en">decode</span><span class="pl-kos">(</span><span class="pl-k">new</span> <span class="pl-v">Uint8Array</span><span class="pl-kos">(</span><span class="pl-s1">buf</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span> </td>
        </tr>

        <tr class="border-0">
          <td id="L73" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="73"></td>
          <td id="LC73" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-kos">}</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto">While <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="731915740" data-permission-text="Title is private" data-url="https://github.com/denoland/deno/issues/8179" data-hovercard-type="issue" data-hovercard-url="/denoland/deno/issues/8179/hovercard" href="https://github.com/denoland/deno/issues/8179">#8179</a> got partially fixed by <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="733254992" data-permission-text="Title is private" data-url="https://github.com/denoland/deno/issues/8199" data-hovercard-type="pull_request" data-hovercard-url="/denoland/deno/pull/8199/hovercard" href="https://github.com/denoland/deno/pull/8199">#8199</a> (nice one btw, thanks for everyone involved!!), the prompt method still has some issues regarding input (related to stdin). For example, the code below doesn't perform as expected when non-ascii characters are used.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const a = prompt('Insert your character');

console.log(`a===a =&gt; ${a === 'a'}`);  // When inserting the character 'a', returns true, as expected!
console.log(`ã===ã =&gt; ${a === 'ã'}`);  // When inserting the character 'ã', returns false, not what we expected."><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-en">prompt</span><span class="pl-kos">(</span><span class="pl-s">'Insert your character'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">`a===a =&gt; <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">a</span> <span class="pl-c1">===</span> <span class="pl-s">'a'</span><span class="pl-kos">}</span></span>`</span><span class="pl-kos">)</span><span class="pl-kos">;</span>  <span class="pl-c">// When inserting the character 'a', returns true, as expected!</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">`ã===ã =&gt; <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">a</span> <span class="pl-c1">===</span> <span class="pl-s">'ã'</span><span class="pl-kos">}</span></span>`</span><span class="pl-kos">)</span><span class="pl-kos">;</span>  <span class="pl-c">// When inserting the character 'ã', returns false, not what we expected.</span></pre></div>
<p dir="auto">Opened a new issue because the other one got closed before this got adressed.</p>