tdf#169147: handle errors creating icu::RegexMatcher
Regression after commit 38f731ff67
(tdf#160478: fix Basic LIKE operator, 2024-04-02).
Change-Id: I4fae01e56cb91d54adba54c3787f576f60f8b1f0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193202
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
This commit is contained in:
@@ -34,8 +34,18 @@ Sub verify_testLike()
|
||||
TestUtil.AssertEqual("a*b" Like "a [*]b", False, "Like9")
|
||||
TestUtil.AssertEqual("axxxxxb" Like "a [*]b", False, "Like10")
|
||||
TestUtil.AssertEqual("a [xyz" Like "a [[]*", True, "Like11")
|
||||
' Invalid pattern
|
||||
Dim caughtError As Integer
|
||||
On Error GoTo expectedErrorHandler
|
||||
TestUtil.AssertEqual("a [xyz" Like "a [*", 42, "") ' Like must fail, will not reach AssertEqual
|
||||
TestUtil.AssertEqual(caughtError, 93, "tdf#169147") ' Invalid string pattern
|
||||
|
||||
Exit Sub
|
||||
|
||||
expectedErrorHandler:
|
||||
caughtError = Err
|
||||
Resume Next
|
||||
|
||||
errorHandler:
|
||||
TestUtil.ReportErrorHandler("verify_testLike", Err, Error$, Erl)
|
||||
End Sub
|
||||
|
||||
@@ -1524,13 +1524,13 @@ void SbiRuntime::StepLIKE()
|
||||
{
|
||||
bTextMode = IsImageFlag( SbiImageFlags::COMPARETEXT );
|
||||
}
|
||||
sal_uInt32 searchFlags = UREGEX_UWORD | UREGEX_DOTALL; // Dot matches newline
|
||||
uint32_t searchFlags = UREGEX_UWORD | UREGEX_DOTALL; // Dot matches newline
|
||||
if( bTextMode )
|
||||
{
|
||||
searchFlags |= UREGEX_CASE_INSENSITIVE;
|
||||
}
|
||||
|
||||
static sal_uInt32 cachedSearchFlags = 0;
|
||||
static uint32_t cachedSearchFlags = 0;
|
||||
static OUString cachedRegex;
|
||||
static std::optional<icu::RegexMatcher> oRegexMatcher;
|
||||
UErrorCode nIcuErr = U_ZERO_ERROR;
|
||||
@@ -1541,6 +1541,12 @@ void SbiRuntime::StepLIKE()
|
||||
icu::UnicodeString sRegex(false, reinterpret_cast<const UChar*>(cachedRegex.getStr()),
|
||||
cachedRegex.getLength());
|
||||
oRegexMatcher.emplace(sRegex, cachedSearchFlags, nIcuErr);
|
||||
if (U_FAILURE(nIcuErr))
|
||||
{
|
||||
// Bad regex; oRegexMatcher has no pattern - would crash in RegexMatcher::reset
|
||||
oRegexMatcher.reset();
|
||||
return Error(ERRCODE_BASIC_BAD_PATTERN);
|
||||
}
|
||||
}
|
||||
|
||||
icu::UnicodeString sSource(false, reinterpret_cast<const UChar*>(value.getStr()),
|
||||
|
||||
Reference in New Issue
Block a user