"Foo" == "Foo" != true (Non printing characters FTL)
Today I ran into a particularly frustrating problem. Basically what was happening was this:
pry> Object.text
=> "Foo"
pry> Object.text == "Foo"
=> false
Obviously this made no sense. After a while I realized there may be a non-printing character which irb was hiding.
pry> Object.text.dump
=> "\"Foo\\u{200b}\""
Now I could see there was a zero width space being added to the string, causing the match to return false. After this, it was a simple matter of removing the unicode character:
Object.text.gsub!(/[\u200b]/,"")
After that:
pry> Object.text == "Foo"
=> true
Cheers, hope this helps!
Written by David Kormushoff
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#