Stories
Slash Boxes
Comments

SoylentNews is people

posted by martyb on Sunday February 23 2020, @10:30AM   Printer-friendly

Helsinki-based software developer, Henri Sivonen, has written a pair of blog posts about UTF-8; why it should be used and how to inform the user agent when it is used.

The first blog post explains problems that can arise when UTF-8 is used without explicitly stating so. Here is a short selection from Why Supporting Unlabeled UTF-8 in HTML on the Web Would Be Problematic:

UTF-8 has won. Yet, Web authors have to opt in to having browsers treat HTML as UTF-8 instead of the browsers Just Doing the Right Thing by default. Why?

I'm writing this down in comprehensive form, because otherwise I will keep rewriting unsatisfactory partial explanations repeatedly as bug comments again and again. For more on how to label, see another writeup.

Legacy Content Won't Be Opting Out

First of all, there is the "Support Existing Content" design principle. Browsers can't just default to UTF-8 and have HTML documents encoded in legacy encodings opt out of UTF-8, because there is unlabeled legacy content, and we can't realistically expect the legacy content to be actively maintained to add opt-outs now. If we are to keep supporting such legacy content, the assumption we have to start with is that unlabeled content could be in a legacy encoding.

In this regard, <meta charset=utf-8> is just like <!DOCTYPE html> and <meta name="viewport" content="width=device-width, initial-scale=1">. Everyone wants newly-authored content to use UTF-8, the No-Quirks Mode (better known as the Standards Mode), and to work well on small screens. Yet, every single newly-authored HTML document has to explicitly opt in to all three, since it isn't realistic to get all legacy pages to opt out.

The second blog post explains how one explicitly communicates to the user agent that UTF-8 is employed in the current document. Always Use UTF-8 & Always Label Your HTML Saying So:

To avoid having to deal with escapes (other than for , &, and "), to avoid data loss in form submission, to avoid XSS when serving user-provided content, and to comply with the HTML Standard, always encode your HTML as UTF-8. Furthermore, in order to let browsers know that the document is UTF-8-encoded, always label it as such. To label your document, you need to do at least one of the following:

  • Put as the first thing after the start tag (i.e. as the first child of head).

    The meta tag, including its ending > character needs to be within the first 1024 bytes of the file. Putting it right after is the easiest way to get this right. Do not put comments before .

  • Configure your server to send the header Content-Type: text/html; charset=utf-8 on the HTTP layer.

  • Start the document with the UTF-8 BOM, i.e. the bytes 0xEF, 0xBB, and 0xBF.

Doing more than one of these is OK.

NB: SoylentNews announced UTF-8 support on 2014-08-18: Site Update: Slashcode 14.08 - Now With UTF-8 Support (And Other News), just 6 months after the site was launched! One of our developers volunteered to do the implementation for them (the code for this site is a fork of the code that underlies slashdot). The offer was declined. A quick check before posting this story still fails to show Unicode/UTF-8 support.

Earlier on SN:
Validating UTF-8 Strings Using As Little As 0.7 Cycles Per Byte (2018)
Announcing UTF-8 Support on SoylentNews (2014)


Original Submission

 
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 4, Touché) by isj on Sunday February 23 2020, @06:58PM (4 children)

    by isj (5249) on Sunday February 23 2020, @06:58PM (#961498) Homepage

    having just ASCII has been sufficient for that for billions of people for decades

    No, it is only sufficient for the English orthography used by 379 million (source: https://en.wikipedia.org/wiki/List_of_languages_by_total_number_of_speakers). [wikipedia.org] Ok, also the Vatican state that has Latin as the official language.

    The rest of use have recognized that the latin alphabet is sufficient only for latin, and have added letters that represents sounds that we use.

    Even for english using only latin letters in orthography has problems: 26 letters to represent 24 consonants and 12-13 vowels. The introduction of the Gutenberg press damaged the English orthography. Because the typesets didn't have them the eth (ð) and thorn (þ) were lost. The Scots lost the yogh (Ȝ) (source: https://www.youtube.com/watch?v=4CtWyh49Mms). [youtube.com]

    I don't have a problem with using ascii for eg. programming language keywords, html keywords/tag-names, etc. It is just like musical notation where the song may be in German but the notation uses italian "keywords" like "forte", "piano", "con pedale". It's fine.

    As for the Unicode Consortiums addition of emojis and other stuff to to Unicode: Their state goal is to include all characters that are used for text and information. So of course Unicode includes the characters latin alphabet, extended latin alphabet, greek, ancient greek, mathematical symbols, hebrew, thai, logographs, typographical signs. They didn't include the fictional klingon characters initially because its users used transliteration. First when the users started using non-transliterated characters unicode got those added. Yes, I still find that silly but it is in line with the stated goal of unicode - people used them for text messages. More info: https://www.youtube.com/watch?v=5OPkGQoPeHk [youtube.com] (includes he really bad idea of a emoji-only chat application)

    Starting Score:    1  point
    Moderation   +2  
       Interesting=1, Touché=1, Total=2
    Extra 'Touché' Modifier   0  
    Karma-Bonus Modifier   +1  

    Total Score:   4  
  • (Score: 2) by FatPhil on Sunday February 23 2020, @08:45PM (3 children)

    by FatPhil (863) <{pc-soylent} {at} {asdf.fi}> on Sunday February 23 2020, @08:45PM (#961544) Homepage
    I'm glad that you don't have any bad memories of our Empire, I'll take that as a compliment. Lots and lots and lots of Indians in that empire, you know.

    You also seem to think that nobody dies or is born, which is weird.
    --
    Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves
    • (Score: 2) by FatPhil on Sunday February 23 2020, @08:47PM (2 children)

      by FatPhil (863) <{pc-soylent} {at} {asdf.fi}> on Sunday February 23 2020, @08:47PM (#961547) Homepage
      Having said that, the fact that you think that you can counter a "has been" with an "is" shows you're really not very good at anything remotely approaching logic.
      --
      Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves
      • (Score: 3, Touché) by isj on Sunday February 23 2020, @09:36PM (1 child)

        by isj (5249) on Sunday February 23 2020, @09:36PM (#961568) Homepage

        The ASCII standard was published in 1963. Has there been billions (assuming short scale: 2.000.000) people with English as their first language that have interacted with computers since then?

        As for India: There are 14 writing scripts used today (source: https://bharatbhashakosh.blogspot.com/2017/06/13-writting-scripts-used-for-indian.html [blogspot.com] ), the most well-known is Devenagari. If ASCII were sufficient then surely they wouldn't use the 13 other scripts?

        If when you wrote "sufficient" you meant "can be transliterated reasonably to ASCII" then perhaps you should have a look at Euroenglish: https://www.englishforums.com/English/FiveYearPhasePlanEuroenglish/gvkwp/post.htm [englishforums.com] After you have read that you may have a better understanding of what non-english speakers think when an ignorant asks if they can't just use ASCII. Note: Italians may argue that your obscure letters J/K/W/X/Y are silly - noone civilised uses those :-)

        • (Score: 2) by FatPhil on Monday February 24 2020, @01:04PM

          by FatPhil (863) <{pc-soylent} {at} {asdf.fi}> on Monday February 24 2020, @01:04PM (#961807) Homepage
          > 1963

          Pfft! ASCII doesn't need to have been existence for it to have been sufficient for their needs. English was the national language of India during the Raj (which it inherited from being the official language under prior EIC control), it's still officially a subsidiary official language of the independent country because it's the de facto inter-regional one, and many regions fought off the attempt to impose Hindi as a national language quite vociferously.

          > If ASCII were sufficient then surely they wouldn't use the 13 other scripts?

          Is there an attempt to have any logic in your arguments at all - you seem to be leaking more and more illogic with every post. If the burger and chips were sufficient for lunch, why did I have bacon and cheese today? Because I wanted to eat them, I had the right to eat them, and I could afford to eat them. But according to your logic, surely I wouldn't have the bacon cheeseburger. But I did. So your logic's worthless.

          > Euroenglish

          Pffft! Noah Webster and Mark Twain did this sensibly to death over a century ago, and the piss-takes go back nearly as far, e.g. Shield's letter to /The Economist/: http://guidetogrammar.org/grammar/twain.htm (wrongly attributed to Twain because Twain did indeed dabble in such matters, and was as much a troll at times).

          > you may have a better understanding of what non-english speakers think when an ignorant asks if they can't just use ASCII

          Pfffft! I've been living in a countries whose character sets don't fit into ASCII *my whole life*. Your whole understanding of my motivation is based on a fantasy in your own head. When I'm chatting in a 7-bit medium, I often continue the decades-long convention of '6' being a letter here. Back in the 90s, {, }, and occasionally | were letters too.
          --
          Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves