I have the following Ruby fragment from a byebug session:
(byebug) target_name
"foo/"
(byebug) target_name.class
String
(byebug) target_name.include?('/')
false
(byebug) "foo/".include?('/')
true
Why does the include? method return false as / is part of foo/?
Ruby version:
ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux]
It is possible that
target_stringcontains some non-ascii characters.For example compare:
and
In the latter example the string contains the "forward slash"
U+2215character encoded as utf-8 bytes.Depending on your specific use case, you could e.g. convert the string to ascii and blindly replace any undefined or invalid character with a
/.Look at the
#encodemethod for more options.