diff options
author | Damien Caliste <dcaliste@free.fr> | 2018-09-18 16:58:44 +0200 |
---|---|---|
committer | Pekka Vuorela <pvuorela@iki.fi> | 2018-09-29 11:51:03 +0000 |
commit | d22dca1bbc17ebc86cb7d7316aacf4b773c3150c (patch) | |
tree | 8e709d7ae476126d490a7864a190ba75421d6936 | |
parent | cb5c76944c0c3a8ee6360564369c1a3cc409255e (diff) |
Do not allow to pass full content type description to setType() method
Nothing avoid or warn when calling setType("text/plain; charset=UTF-8").
Later calls to subType() or charset() return a wrong value then. Patch
simply checks that ';' or '/' is not part of the argument in setType().
Change-Id: I1839c2a5800328e00f422054d5c19e9797be1a94
Reviewed-by: Pekka Vuorela <pvuorela@iki.fi>
Reviewed-by: Matthew Vogt <matthew.vogt@qinetic.com.au>
-rw-r--r-- | src/libraries/qmfclient/qmailmessage.cpp | 10 | ||||
-rw-r--r-- | tests/tst_qmailmessageheader/tst_qmailmessageheader.cpp | 8 |
2 files changed, 13 insertions, 5 deletions
diff --git a/src/libraries/qmfclient/qmailmessage.cpp b/src/libraries/qmfclient/qmailmessage.cpp index a04abc67..b6f16ed2 100644 --- a/src/libraries/qmfclient/qmailmessage.cpp +++ b/src/libraries/qmfclient/qmailmessage.cpp @@ -2569,13 +2569,13 @@ QByteArray QMailMessageContentType::type() const */ void QMailMessageContentType::setType(const QByteArray& type) { - if (type.isEmpty()) - { + if (type.isEmpty()) { // Note - if there is a sub-type, setting type to null will destroy it setContent(type); - } - else - { + } else if (type.contains(';') || type.contains('/')) { + qWarning() << Q_FUNC_INFO << "wrong usage of setType(), consider using setSubType() or setParameter()" << type; + + } else { QByteArray content(type); QByteArray secondaryType(subType()); diff --git a/tests/tst_qmailmessageheader/tst_qmailmessageheader.cpp b/tests/tst_qmailmessageheader/tst_qmailmessageheader.cpp index 92c724cc..34d8ae63 100644 --- a/tests/tst_qmailmessageheader/tst_qmailmessageheader.cpp +++ b/tests/tst_qmailmessageheader/tst_qmailmessageheader.cpp @@ -1322,6 +1322,14 @@ void tst_QMailMessageContentType::setType() QCOMPARE( type2.type(), QByteArray() ); QCOMPARE( type2.subType(), QByteArray() ); QCOMPARE( type2.toString(), QByteArray("Content-Type:; charset=us-ascii") ); + + // Illegal arguments to setType() + QMailMessageContentType type3("image/jpeg"); + // Set the type and charset + type3.setType("text/plain; charset=UTF-8"); + QCOMPARE( type3.type(), QByteArray("image") ); + QCOMPARE( type3.subType(), QByteArray("jpeg") ); + QVERIFY( type3.charset().isEmpty() ); } void tst_QMailMessageContentType::subType() |