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:
Mike Kaganski
2025-10-30 18:18:57 +01:00
parent 11966e9821
commit 3ab2560526
2 changed files with 18 additions and 2 deletions
+10
View File
@@ -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
+8 -2
View File
@@ -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()),