Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the message "Invalid byte 2 of a 3-byte UTF-8 sequence" mean?

I changed a file in Orbeon Forms, and the next time I load the page, I get an error message saying Invalid byte 2 of a 3-byte UTF-8 sequence. How can I solve this problem?

like image 929
avernet Avatar asked Jul 03 '12 22:07

avernet


People also ask

What does an invalid start byte sequence in UTF 8 mean?

Why does an UTF-8 invalid byte sequence error happen? Ruby's default encoding since 2.0 is UTF-8. This means that Ruby will treat any string you input as an UTF-8 encoded string unless you tell it explicitly that it's encoded differently. Let's use the Å character from the introductory diagram to present this problem.

What is an invalid byte?

Explanation: This error occurs when you send text data, but either the source encoding doesn't match that currently set on the database, or the text stream contains binary data like NUL bytes that are not allowed within a string.


2 Answers

A three byte UTF-8 sequence looks like:

1110xxxx 10xxxxxx 10xxxxxx

Your error message may mean that the first byte of the three is incorrectly flagging the start of a three byte sequence or else that the second byte is malformed.

As @avernet says, you need to make sure that all elements in your system are producing and expecting UTF-8.

like image 31
rossum Avatar answered Oct 25 '22 16:10

rossum


This happens when Orbeon Forms reads an XML file and expects it to use the UTF-8 encoding, but somehow the file isn't properly encoded in UTF-8. To solve this, make sure that:

  1. You have an XML declaration at the beginning of the file saying the file is in UTF-8:

    <?xml version="1.0" encoding="UTF-8" ?>
    
  2. Your editor is XML-aware, so it can parse the XML declaration and consequently use the UTF-8 encoding. If your editor isn't XML aware, and you don't want to use another editor, look for an option or preference allowing you to specify that the editor must use UTF-8.

like image 142
avernet Avatar answered Oct 25 '22 17:10

avernet