Fix bug in mime type magic rules with Qt 6.2

There was a bug in the copying and comparison of mime magic rules, that
did not copy/compare the sub-rules.

With Qt 5 this was probably never actually used, because we save the
magic rules in a QList, and that didn't use MimeMagicRule as "values",
but internally used pointers to heap-allocated objects, so e.g.
appending a list of rules to another list of rules would only copy the
pointers to the actual objects (as long as the items were never
modified).

In Qt 6, QList has the same semantics as QVector, so MimeMagicRule is
actually used as values, which uses the copy operations. As a result,
the moment the MimeMagicRule was copied from the parser to the mime
type, it would loose its sub-rules. Which breaks the whole mime magic
logic, and leads to wrong mime type resolution, e.g. for *.ui files.

Change-Id: I90c46264423f18f73a6efc01887a0b8b6199d35d
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Eike Ziller
2021-09-14 11:54:13 +02:00
parent 7e965629b0
commit 1d466499f6

View File

@@ -359,8 +359,9 @@ MimeMagicRule::MimeMagicRule(MimeMagicRule::Type theType,
}
}
MimeMagicRule::MimeMagicRule(const MimeMagicRule &other) :
d(new MimeMagicRulePrivate(*other.d))
MimeMagicRule::MimeMagicRule(const MimeMagicRule &other)
: m_subMatches(other.m_subMatches)
, d(new MimeMagicRulePrivate(*other.d))
{
}
@@ -369,13 +370,13 @@ MimeMagicRule::~MimeMagicRule() = default;
MimeMagicRule &MimeMagicRule::operator=(const MimeMagicRule &other)
{
*d = *other.d;
m_subMatches = other.m_subMatches;
return *this;
}
bool MimeMagicRule::operator==(const MimeMagicRule &other) const
{
return d == other.d ||
*d == *other.d;
return (d == other.d || *d == *other.d) && m_subMatches == other.m_subMatches;
}
MimeMagicRule::Type MimeMagicRule::type() const