QV4: Fix formatting options for the search component of UrlObject
This fix changes the way the search component of UrlObjects is formatted
by passing the correct options to QUrl::query. Namely, the
EncodeDelimiters flag is no longer set. This now allows for correct
encoding of backslashes in search strings.
Amends 6cca731f3e
.
Pick-to: 6.5
Task-number: QTBUG-111014
Change-Id: Iee544dfc7ad6ba374601c8ec4690d11bf07c9b6a
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
parent
1fdca936fb
commit
af4cd4763a
|
@ -248,7 +248,10 @@ QString UrlObject::search() const
|
|||
if (auto url = QUrl(href()); !url.hasQuery() || url.query().isEmpty())
|
||||
return QLatin1String("");
|
||||
|
||||
return QLatin1Char('?') + url.query(QUrl::ComponentFormattingOptions(QUrl::ComponentFormattingOption::FullyEncoded));
|
||||
constexpr auto options = QUrl::ComponentFormattingOption::EncodeSpaces
|
||||
| QUrl::ComponentFormattingOption::EncodeUnicode
|
||||
| QUrl::ComponentFormattingOption::EncodeReserved;
|
||||
return u'?' + url.query(options);
|
||||
}
|
||||
|
||||
QUrl UrlObject::toQUrl() const
|
||||
|
|
|
@ -116,6 +116,14 @@ void tst_urlobject::urlObject_search_data()
|
|||
<< "var url = new URL(\"http://google.com/search/?a=㉽\");"
|
||||
"url.search"
|
||||
<< "?a=%E3%89%BD";
|
||||
QTest::newRow("backslash")
|
||||
// The JS string in the C++ source ends in 4 backslashes.
|
||||
// The C++ compiler turns that into 2 backslashes.
|
||||
// QV4 receives source code containing a string literal ending in two backslashes.
|
||||
// The resulting JS string ends in a single backslash.
|
||||
<< "var url = new URL('http://google.com/search/?q=\\\\');"
|
||||
"url.search"
|
||||
<< "?q=\\";
|
||||
}
|
||||
|
||||
void tst_urlobject::urlObject_href()
|
||||
|
|
Loading…
Reference in New Issue