Skip to content

Non-utf8 encoding of internal client-side JavaScript files? #678

Closed

Description

@MartinMa

All of my js source files (browser and web) are encoded using utf-8 (without BOM). However, I happen to experience the following issue.

When I use "special characters" in my web JavaScript files, they are somehow converted to another encoding. For example, printing ä to the console (DevTools) using console.log produces garbage. Right now, I'm getting around this problem by using the escaped versions of all special characters.

See this example program to illustrate the problem:

On browser side after mainWindow.loadUrl:

mainWindow.openDevTools();

mainWindow.webContents.on('did-finish-load', function () {
  mainWindow.webContents.send('test-data', {msg: 'ä'});
});

index.html:

<html>
<body>
  <script>
    require('ipc').on('test-data', function(test) {
      console.log(test.msg);
      console.log('ä');
    });
  </script>
</body>
</html>

produces this result:

ä
ä

So, the ä send via ipc from node is encoded correctly, but the ä from index.html is garbled. Note that index.html is utf-8 encoded. It actually makes no difference, if I include the js code from a separate file.

Tested system: Windows 7
atom-shell: v0.17.1

Activity

  1. zcbenz commented on Nov 7, 2014

    @zcbenz
    Contributor

    As I tested in Chrome 38, console.log('ä') printed ä in console too, you should report this bug to Chromium project.

  2. MartinMa commented on Nov 7, 2014

    @MartinMa
    ContributorAuthor

    @zcbenz That seems weird to me. I couldn't reproduce this behavior using different versions of Chrome on Windows.
    Windows 7 SP1, Chrome Version 39.0.2171.52 beta-m
    Windows 10 (Build 9860), Chrome Version 38.0.2125.111 m

    devtools2

  3. zcbenz commented on Nov 7, 2014

    @zcbenz
    Contributor

    You need to write console.log('ä') in HTML file to reproduce, executing it under devtools works in atom-shell too.

  4. kostia commented on Sep 22, 2015

    @kostia
    Contributor

    I have the same issue with Version 0.33.1 on OSX 10.10.5:

    <!-- html.index -->
    
    <!DOCTYPE html>
    <html>
      <head><title>Test</title></head>
      <body>
        <textarea id="input"></textarea>
        <script>
          window.document.getElementById('input').value = "ä";
        </script>
      </body>
    </html>

    will produce

    bildschirmfoto 2015-09-23 um 01 48 05

  5. zcbenz commented on Sep 23, 2015

    @zcbenz
    Contributor

    To show HTML pages that don't use UTF-8 encoding, you should explicitly set page's encoding like this:

    <head>
    <meta charset="UTF-8">
    </head>
  6. kostia commented on Sep 23, 2015

    @kostia
    Contributor

    Thanks @zcbenz, that worked for me!

    However, "ä" is UTF-8 (http://www.utf8-zeichentabelle.de). I somehow assumed, that a document with an HTML5 doctype would have UTF-8 charset by-default. But it does not. Should the Quick-Start example include the right charset? https://github.com/atom/electron/blob/master/docs/tutorial/quick-start.md

    @MartinMa Does setting the correct encoding resolve your problem?

  7. zcbenz commented on Sep 23, 2015

    @zcbenz
    Contributor

    Should the Quick-Start example include the right charset? https://github.com/atom/electron/blob/master/docs/tutorial/quick-start.md

    I think we should, you can send a pull request for that.

  8. added a commit that references this issue on Sep 23, 2015
    334c28d
  9. MartinMa commented on Sep 30, 2015

    @MartinMa
    ContributorAuthor

    @kostia Thanks, I just tested this with the current version v0.33.3 (ia32) on Windows. Explicitly setting the encoding to UTF-8 resolves all problems for inline scrips and referenced scripts. 👍

    I thought, somehow, chromium would figure out the encoding automatically or at least default to UTF-8. None of it is the case. It seems to default to another charset. On a German Windows 8.1 it seems to be Windows-1252.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions