Add a function that scrubs URL queries from strings.

In some cases, URL queries contain auth information. For cases where error
strings are passed from other libraries, such as from gstreamer, add a utility
function, ScrubUrlQueries, to strip queries from URLs in strings.
This commit is contained in:
Jim Broadus 2020-02-15 15:59:19 -08:00 committed by John Maguire
parent a0bb8ab3a1
commit 5dd6d6725a
2 changed files with 10 additions and 0 deletions

View File

@ -760,6 +760,13 @@ QByteArray GetUriForGstreamer(const QUrl& url) {
return url.toEncoded();
}
QString ScrubUrlQueries(const QString& str) {
// If the URL isn't followed by whitespace, this will eat extra characters.
QRegExp rx("((?:http|https)://\\S*\\?)\\S*");
// QString::replace is non const, so operate on a copy.
return QString(str).replace(rx, "\\1 (query removed)");
}
} // namespace Utilities
ScopedWCharArray::ScopedWCharArray(const QString& str)

View File

@ -164,6 +164,9 @@ int GetThreadId();
bool IsLaptop();
QString SystemLanguageName();
// Scrub messages for to remove queries, which may include auth info, from URLs.
QString ScrubUrlQueries(const QString& str);
} // namespace Utilities
class ScopedWCharArray {