File tree Expand file tree Collapse file tree 4 files changed +26
-9
lines changed Expand file tree Collapse file tree 4 files changed +26
-9
lines changed Original file line number Diff line number Diff line change 5
5
----
6
6
7
7
* Added operators ` == ` and ` != ` for ` JsonDocument ` , ` ElementProxy ` , and ` MemberProxy `
8
+ * Fixed comparison of ` JsonVariant ` when one contains a linked string and the other contains an owned string (issue #1051 )
8
9
9
10
v6.11.2 (2019-07-08)
10
11
-------
Original file line number Diff line number Diff line change @@ -16,15 +16,18 @@ namespace ARDUINOJSON_NAMESPACE {
16
16
enum {
17
17
VALUE_MASK = 0x7F ,
18
18
19
+ OWNERSHIP_BIT = 0x01 ,
19
20
VALUE_IS_NULL = 0 ,
20
- VALUE_IS_LINKED_RAW = 0x01 ,
21
- VALUE_IS_OWNED_RAW = 0x02 ,
22
- VALUE_IS_LINKED_STRING = 0x03 ,
23
- VALUE_IS_OWNED_STRING = 0x04 ,
24
- VALUE_IS_BOOLEAN = 0x05 ,
25
- VALUE_IS_POSITIVE_INTEGER = 0x06 ,
26
- VALUE_IS_NEGATIVE_INTEGER = 0x07 ,
27
- VALUE_IS_FLOAT = 0x08 ,
21
+ VALUE_IS_LINKED_RAW = 0x02 ,
22
+ VALUE_IS_OWNED_RAW = 0x03 ,
23
+ VALUE_IS_LINKED_STRING = 0x04 ,
24
+ VALUE_IS_OWNED_STRING = 0x05 ,
25
+
26
+ // CAUTION: no OWNERSHIP_BIT below
27
+ VALUE_IS_BOOLEAN = 0x06 ,
28
+ VALUE_IS_POSITIVE_INTEGER = 0x08 ,
29
+ VALUE_IS_NEGATIVE_INTEGER = 0x0A ,
30
+ VALUE_IS_FLOAT = 0x0C ,
28
31
29
32
COLLECTION_MASK = 0x60 ,
30
33
VALUE_IS_OBJECT = 0x20 ,
Original file line number Diff line number Diff line change @@ -101,7 +101,9 @@ class VariantData {
101
101
}
102
102
103
103
bool equals (const VariantData &other) const {
104
- if (type () != other.type ()) return false ;
104
+ // Check that variant have the same type, but ignore string ownership
105
+ if ((type () | OWNERSHIP_BIT) != (other.type () | OWNERSHIP_BIT))
106
+ return false ;
105
107
106
108
switch (type ()) {
107
109
case VALUE_IS_LINKED_STRING:
Original file line number Diff line number Diff line change @@ -286,6 +286,17 @@ TEST_CASE("JsonVariant comparisons") {
286
286
REQUIRE_FALSE (variant1 == variant3);
287
287
}
288
288
289
+ SECTION (" Variants containing mixed strings (issue #1051)" ) {
290
+ variant1.set (" hello" );
291
+ variant2.set (std::string (" hello" ));
292
+
293
+ REQUIRE (variant1 == variant2);
294
+ REQUIRE_FALSE (variant1 != variant2);
295
+
296
+ REQUIRE (variant2 == variant1);
297
+ REQUIRE_FALSE (variant2 != variant1);
298
+ }
299
+
289
300
SECTION (" Variants containing double" ) {
290
301
variant1.set (42.0 );
291
302
variant2.set (42.0 );
You can’t perform that action at this time.
0 commit comments