banditcpp/bandit

Not respecting zero byte (`\0`) while logging mismatch of std::string.

OpatrilPeter opened this issue · 3 comments

In current solution, following code

AssertThat("abc\0def"s, Equals("abc"));

leads to error:

There were failures!

Test ....:
...: Expected: equal to abc
Actual: abc

(IMHO it should print what printing the std::string would - abcdef - or in ideal world, something like abc\x00def)
The message for the exception is generated correctly, problem lies in printing it in failure_formatter: it uses what() method which returns const char *, so it simply ends on first \0 occurence.

Yes, the C++ standard defines what() to return a null-terminated const char * string, hence the issue cannot be solved on that end. One could make a default-Stringizer for strings in Snowhouse that converts non-printable characters (like \0) to something printable. I am however not sure if this is always desirable...

As I see it, a major use of this Stringizer is to be able to compare values, thus it seems like a sensible default to highlight otherwise undetectable differences.

I close this issue here; the respective issue is in Snowhouse (banditcpp/snowhouse#40). However, I have no idea when I get to it.