Details
-
Bug
-
Resolution: Invalid
-
P3: Somewhat important
-
None
-
5.9, 5.12.5, 5.13.2
-
None
Description
Starting from Qt 5.9, when QByteArray::toHex(char separator) was introduced, the special case when the size of the input QByteArray is zero returns a null QByteArray.
Thus, QByteArray("").toHex().isNull() is true, while I really expect it to be false. I don't think this is intended.
The commit which introduced this kind of breaking change is 615027129d3d5e12a6e2f5d02d2af8320cc58ea7.
I think if we handle the special case of an empty QByteArray, so should we handle a null input too, and return an empty / null result respectively.
Interestingly, there are test cases which test exactly these cases: null should stay null and empty should stay empty. But these test cases succeed since an empty (non-null) QByteArray compares equal to a null QByteArray().
In general: The documentation tells us that Qt distinguishes between a null and empty QByteArray for historical reasons, however, if this is the case, the documentation of functions which behave like this should document this behavior (i.e. "If this is empty, a null QByteArray is returned" or the like). It is not clear if this is "correct behavior".