If 'name' contained non-ASCII characters, the comparison raised a UnicodeEncodeError on Python 2. Backport of 63c5c987 from master