Commit 362f1b4
committed
QCborValue: make QDateTime constructor consistent with fromCbor
The QCborValue(const QDateTime &) constructor unconditionally set the
type to QCborValue::DateTime. For a null QDateTime, toString() yields an
empty string, so the value was encoded as tag 0 wrapping an empty text
string, 0(""). An empty string is not a valid date/time. RFC 3339's ABNF
requires both a date and a time:
iso-date-time = date "T" time
and QDateTime::fromString() agrees by returning an invalid QDateTime.
If we tried decoding that with fromCbor(), it would correctly fail,
leaving type() to Tag and breaking equality over toCbor()/fromCbor()
round-trip (though the tagged values still compared equal).
Rather than keep two notions of what a DateTime is, let's add a central
function to set it. A valid QDateTime is promoted to DateTime as before;
a null one stays a plain Tag(0, ""), matching what fromCbor() produces.
Fixes: QTBUG-149559
Pick-to: 6.12 6.11 6.8
Change-Id: I3502380cd23dbc867fdefffda35f95940c6e0091
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>1 parent 3f2e5bc commit 362f1b4
2 files changed
Lines changed: 22 additions & 14 deletions
File tree
- src/corelib/serialization
- tests/auto/corelib/serialization/qcborvalue
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
752 | 752 | | |
753 | 753 | | |
754 | 754 | | |
| 755 | + | |
755 | 756 | | |
756 | 757 | | |
757 | 758 | | |
| |||
798 | 799 | | |
799 | 800 | | |
800 | 801 | | |
801 | | - | |
802 | | - | |
803 | | - | |
804 | | - | |
805 | | - | |
806 | | - | |
807 | | - | |
808 | | - | |
809 | | - | |
| 802 | + | |
| 803 | + | |
810 | 804 | | |
811 | 805 | | |
812 | 806 | | |
| |||
2086 | 2080 | | |
2087 | 2081 | | |
2088 | 2082 | | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
2089 | 2095 | | |
2090 | 2096 | | |
2091 | 2097 | | |
| |||
2100 | 2106 | | |
2101 | 2107 | | |
2102 | 2108 | | |
2103 | | - | |
| 2109 | + | |
| 2110 | + | |
2104 | 2111 | | |
2105 | | - | |
2106 | | - | |
2107 | | - | |
| 2112 | + | |
2108 | 2113 | | |
2109 | 2114 | | |
2110 | 2115 | | |
| |||
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2417 | 2417 | | |
2418 | 2418 | | |
2419 | 2419 | | |
| 2420 | + | |
| 2421 | + | |
| 2422 | + | |
2420 | 2423 | | |
2421 | 2424 | | |
2422 | 2425 | | |
| |||
2771 | 2774 | | |
2772 | 2775 | | |
2773 | 2776 | | |
2774 | | - | |
| 2777 | + | |
2775 | 2778 | | |
2776 | 2779 | | |
2777 | 2780 | | |
| |||
0 commit comments