Skip to content

Polymer does not display cyrillic characters correctly #498

Closed
@ujeenator

Description

Hi, I just discovered a problem with cyrillic text in Polymer.

When I use cyrillic text in the polymer element definition, the browser display it like it not understand the encoding.

I found the place in Polymer sources which cause the problem.

Polymer version I used:
0.2.4

File:
/HMTLImports/src/Parser.js

Line:
220

Source code:

function generateScriptDataUrl(script) {
  var scriptContent = generateScriptContent(script), b64;
  try {
    b64 = btoa(scriptContent);
  } catch(e) {
    b64 = btoa(unescape(encodeURIComponent(scriptContent)));
    console.warn('Script contained non-latin characters that were forced ' +
      'to latin. Some characters may be wrong.', script);
  }
  return 'data:text/javascript;base64,' + b64;
}

Description:
When encoding script-string in Base64 data URI, browser don't "undestand" cyrillic symbols.

My solution is to encode script-string with only "encodeURIComponent" function and supply it with "data:text/javascript;charset=utf-8," URI header (instead of "data:text/javascript;base64," header).

Then everything works correctly.

My patch:

function generateScriptDataUrl(script) {
    var scriptContent = generateScriptContent(script), b64;
  try {
    b64 = btoa(scriptContent);
  } catch(e) {
    console.warn('Script contained non-latin characters that were forced ' +
      'to latin. Some characters may be wrong.', script);
    b64 = encodeURIComponent(scriptContent);
    return "data:text/javascript;charset=utf-8," + b64;
  }
  return 'data:text/javascript;base64,' + b64;
}

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions