Accepting selected projects for Q2 2024 Check availability →
SERVER 02SYSTEM ONLINELAST SYNC: 03:17:44RSS 2.0 — ONLINE
HALF ASSEDTECHNICAL NOTES_
EST. 1999ISSUE 04.2BEST VIEWED AT 1024 × 768
TECHNICAL NOTES / TECHNICAL NOTES / CHARACTER ENCODING / RECORD b283de
[CHARACTER ENCODING]NOTE

Keeping UTF-8 intact through an HTML application

POSTED: 11.12.2003AUTHOR: ADMIN2 MIN READCOMMENTS: 0

An encoding declaration tells a browser how to interpret bytes. It does not convert those bytes. When an accented name becomes several unexpected characters, inspect the path from input to storage and back before changing declarations at random.

Check the bytes and the declaration

Save templates in the selected encoding and configure the server to send Content-Type: text/html; charset=UTF-8. An HTML 4 http-equiv Content-Type meta element can provide the corresponding declaration in the document. Keep these consistent. A conflicting HTTP header takes precedence over the document declaration, so inspect the response headers rather than relying only on View Source.

Follow a value through each boundary

Test a name containing an accent, a pound sign and a character outside the Western European set. Inspect what the form sends, what the application stores and what it reads back. Confirm what the installed database and client library support; do not assume that every byte string is automatically converted. Convert only at a boundary where the source encoding is known.

Keep escaping separate from conversion

HTML escaping protects markup characters such as ampersands and angle brackets. It does not repair text decoded using the wrong character set. Numeric character references can represent characters in HTML, but storing all text as such references complicates email, searching and other output. Retain original backups before converting existing records, and test for data already converted once.

ROUND-TRIP TEST

Save, edit, search for and export the same test record. Correct display immediately after submission can hide a fault in the stored value.

References

W3C: HTML 4.01 document representation

RFC 3629: UTF-8, November 2003