diff options
| author | Andreas Hartmetz <ahartmetz@gmail.com> | 2025-09-04 18:31:37 +0200 |
|---|---|---|
| committer | Andreas Hartmetz <ahartmetz@gmail.com> | 2025-09-05 18:38:17 +0200 |
| commit | 3444922a93b8087a474ef063217a2199178a551d (patch) | |
| tree | bb694973dc7c6ed0490b938085f7025fcd199196 /src/qml/jsruntime/qv4urlobject.cpp | |
| parent | a57014b00e0390c256b378ea66443e0ce8d32279 (diff) | |
Fix JS URL behavior when setting an empty search string
This code needs to bridge the following difference:
In JS:
"" search string -> ""
"?" search string -> "?"
In QUrl:
null search string -> ""
"" search string -> "?"
Pick-to: 6.10
Change-Id: I0b1bf64f0b251eba75b852adee5db05abe87f6fe
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4urlobject.cpp')
| -rw-r--r-- | src/qml/jsruntime/qv4urlobject.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4urlobject.cpp b/src/qml/jsruntime/qv4urlobject.cpp index 454240f8ca..6790d4c289 100644 --- a/src/qml/jsruntime/qv4urlobject.cpp +++ b/src/qml/jsruntime/qv4urlobject.cpp @@ -214,8 +214,14 @@ bool UrlObject::setSearch(QString search) { QUrl url = toQUrl(); - if (search.startsWith(QLatin1Char('?'))) + if (search.startsWith(QLatin1Char('?'))) { search = search.mid(1); + } else if (search.isEmpty()) { + // In JS, setting an empty query removes the '?' as well. QUrl only does that for a null QString. + // The way to get a lone '?' in JS is to set the search property to "?". That is why this is in + // the else branch. + search = QString(); // it's null now + } url.setQuery(search); |
