Created
December 7, 2011 23:02
-
-
Save gcarothers/1445180 to your computer and use it in GitHub Desktop.
Example HTML5 UTF-8 string with errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html_example = "41 98 BA 42 E2 98 43 E2 98 BA E2 98" | |
bytes_in_hex = html_example.split(" ") | |
html_example_bytes = ''.join((chr(int(x,16)) for x in bytes_in_hex)) | |
# html_example_bytes.decode('utf-8') #Throws error | |
replaced_unicode = html_example_bytes.decode('utf-8', 'replace') | |
assert(u'A\ufffd\ufffdB\ufffdC\u263a\ufffd' == replaced_unicode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment