QRegularExpression: match newlines when converting wildcards
A * or a ? in a wildcard pattern is allowed to match any character, including newlines. When converting a wildcard pattern to a PCRE, * and ? were converted to ., which by default does _not_ match over newlines (/s is necessary). There isn't a metacharacter that matches everything, so either we modify the returned pattern to enable dot-matches-all (for instance, by wrapping the returned expression in (?s:...)), or use a character class that includes everything. Picking this last approach for simplicity. Change-Id: I86703f654e3414783427c4c8e0bb018885b42e54 Fixes: QTBUG-113676 Pick-to: 6.5 Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
c5221f6be0
commit
313bb32364
@ -1942,7 +1942,9 @@ QString QRegularExpression::wildcardToRegularExpression(QStringView pattern, Wil
|
||||
|
||||
const GlobSettings settings = [options]() {
|
||||
if (options.testFlag(NonPathWildcardConversion)) {
|
||||
return GlobSettings{ u'\0', u".*", u"." };
|
||||
// using [\d\D] to mean "match everything";
|
||||
// dot doesn't match newlines, unless in /s mode
|
||||
return GlobSettings{ u'\0', u"[\\d\\D]*", u"[\\d\\D]" };
|
||||
} else {
|
||||
#ifdef Q_OS_WIN
|
||||
return GlobSettings{ u'\\', u"[^/\\\\]*", u"[^/\\\\]" };
|
||||
|
@ -2491,6 +2491,10 @@ void tst_QRegularExpression::wildcard_data()
|
||||
addRow("foo/(?)/bar", "foo/(Q)/bar", true, true);
|
||||
|
||||
addRow("foo*bar", "foo/fie/baz/bar", false, true);
|
||||
addRow("foo*bar", "foo bar", true, true);
|
||||
addRow("foo*bar", "foo\tbar", true, true);
|
||||
addRow("foo*bar", "foo\nbar", true, true);
|
||||
addRow("foo*bar", "foo\r\nbar", true, true);
|
||||
|
||||
// different anchor modes
|
||||
addRow("foo", "afoob", false, false, true);
|
||||
|
Loading…
Reference in New Issue
Block a user