String == String does not work with embedded NUL characters
https://github.com/arduino/ArduinoCore-API/blob/7f8de5869ee3de7a915bf1db64313c08595b3ac3/api/String.cpp#L445 and https://github.com/arduino/ArduinoCore-API/blob/7f8de5869ee3de7a915bf1db64313c08595b3ac3/api/String.cpp#L445 should use memcmp() to make sure that a String object can be compared to another String object that has embedded NUL characters
Also, https://github.com/arduino/ArduinoCore-API/blob/7f8de5869ee3de7a915bf1db64313c08595b3ac3/api/String.cpp#L467 https://github.com/arduino/ArduinoCore-API/blob/7f8de5869ee3de7a915bf1db64313c08595b3ac3/api/String.cpp#L492 https://github.com/arduino/ArduinoCore-API/blob/7f8de5869ee3de7a915bf1db64313c08595b3ac3/api/String.cpp#L498 have the same problem.
You can debate if there is a change needed to https://github.com/arduino/ArduinoCore-API/blob/7f8de5869ee3de7a915bf1db64313c08595b3ac3/api/String.cpp#L470, but String::equalsIgnoreCase implies only printable characters.
Did you see #97? It is related and I think it might solve your issue (but it's been too long since I wrote it, so I cannot recall exactly).
Yes, I saw your pull request (and commented on it). As far as I can see, it still has strcmp() calls in it... please correct me if I'm wrong!
Christ van Willegen
Instead of strcmp(), try using stricmp(). It may work
@cvwillegen, seems you're right, I should probaly dust off that PR sometime and also fix those calls...
@Prath06, but it seems that stricmp() just makes the comparison case insensitive, and also it does not seem to be a standard libc function at all. How would this help here?
In C, C strings are just an array of chars terminated by NULL. That is how strcmp(), strcpy(), etc know where the end of the string is. The Arduino String class does a nice job hiding those implementation details, but the fact remains: embedded nulls in Strings WILL BREAK THINGS.
In C, C strings are just an array of chars terminated by NULL.
Sure, that's how C strings work. But the String class is something different - it's a buffer with an explicit length, so there is no reason why embedded nuls could not be supported by it.
Sure, we could define this as an (artificial) limitation on the String class as well, which could make its implementation simpler (because it can then just use the C-string functions for its processing without any extra work), but changes made to String in the past suggest that this is not the intention, and the goal is to make String work even with embedded nuls.
memcmp is a standard function in the C library...