diff options
| author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2023-05-21 17:33:17 +0200 |
|---|---|---|
| committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2023-05-23 00:03:37 +0200 |
| commit | 313bb32364e106e111b8518b786c4364770aaaac (patch) | |
| tree | 0a8752cba479e1876c06b829fdf09ca53013db3e | |
| parent | c5221f6be00c16187e0abf008b33c230fea56c29 (diff) | |
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>
| -rw-r--r-- | src/corelib/text/qregularexpression.cpp | 4 | ||||
| -rw-r--r-- | tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp | 4 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp index 2c83d122a3b..07e2f7965e4 100644 --- a/src/corelib/text/qregularexpression.cpp +++ b/src/corelib/text/qregularexpression.cpp @@ -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"[^/\\\\]" }; diff --git a/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp index 5a8dc2b3736..02c2725ba4d 100644 --- a/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp @@ -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); |
