Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
Special characters not being rendered properly across different environments

I am working with this library https://github.com/unicode-cldr/cldr-localenames-modern in order to get a list of countries. Some of them have special characters that for some reason the browsers (Chrome and FF) are not rendering properly.

I created this codesandbox https://codesandbox.io/s/zen-jackson-qt9i46?file=/src/App.js where I am using the exact same code that the library is using. Weirdly, in the codesandbox there are no issues at all.

This is the list of countries => https://github.com/unicode-cldr/cldr-localenames-modern/blob/master/main/en/territories.json

On this function I tried 2 different things:

const sortCountryOptions = (options) => {
  return Object.keys(options)
    .filter(key => key.length === 2 && !['EU', 'EZ', 'UN', 'XA', 'XB', 'ZZ'].includes(key))
    .sort((a, b) => {
      const an = (Array.isArray(options[a])) ? options[a][0] : options[a];
      const bn = (Array.isArray(options[b])) ? options[b][0] : options[b];
      return an < bn ? -1 : (an > bn ? 1 : 0);
    })
    .reduce((obj, key) => {
      obj[key] = options[key];
      return obj;
    }, {});
};

const cldr = () => {
  const list = cldrLocaleNames.main.en.localeDisplayNames.territories;
  // when I call this list, I am getting the bad characters. 
  return sortCountryOptions(list);
};

I changed this an < bn ? -1 : (an > bn ? 1 : 0) to this an.localeCompare(bn) but the same keeps going.

On the screenshot below you can check on every column, the name in the middle of each, have problems. enter image description here

I do not know if this could be something wrong with a webpack config, also, when I deploy to another environment, the error is gone or just different.

And actually the problem is not by the time I render the objects because I detected that this issue on my project happens exactly here: const list = cldrLocaleNames.main.en.localeDisplayNames.territories;

Any ideas?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Character Encoding

It's a character encoding problem, but you will need to pinpoint the cause. For example, using the wrong meta tag will cause "St. Barthélemy" to appear as "St. Barthélemy". You can demonstrate this by creating and opening the two simple web pages below, each with a different encoding. Yet, the problem can be something other than a meta tag. For example, how the data is read from the server.

This related SO question might be helpful: utf-8 special characters not displaying

8859 Encoding - displays incorrectly in the browser

<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
</head>
<body>
    St. Barthélemy
</body>
</html>

UTF-8 Encoding - displays correctly in the browser

<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
    St. Barthélemy
</body>
</html>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda