Skip to content

Instantly share code, notes, and snippets.

@mxey
Created December 19, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mxey/56692d2f2db239a5c229 to your computer and use it in GitHub Desktop.
Save mxey/56692d2f2db239a5c229 to your computer and use it in GitHub Desktop.
root@ubuntu-512mb-fra1-01:~# touch $(printf '\xff\xff\xffäöü')
root@ubuntu-512mb-fra1-01:~# ls
???äöü
>>> os.listdir(b".")[1]
b'\xff\xff\xff\xc3\xa4\xc3\xb6\xc3\xbc'
>>> os.listdir(".")[1]
'\udcff\udcff\udcffäöü'
>>> print(os.listdir(".")[1])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in position 0: surrogates not allowed
[1] pry(main)> Dir.glob("*")[0]
=> "\xFF\xFF\xFFäöü"
[2] pry(main)> puts Dir.glob("*")[0]
???äöü
=> nil
[3] pry(main)> Dir.glob("*")[0].valid_encoding?
=> false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment