Skip to content

Commit

Permalink
Merge pull request #1832 from Expensify/main
Browse files Browse the repository at this point in the history
Update expensify_prod branch
  • Loading branch information
iwiznia authored Jul 30, 2024
2 parents 69ecfbf + 116d7d0 commit f7a7694
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libstuff/libstuff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2865,8 +2865,10 @@ string SREReplace(const string& regExp, const string& input, const string& repla
if (i == 0 && result == PCRE2_ERROR_NOMEMORY) {
// This is the expected case on the first run, there's not enough space to store the result, so we allocate the space and do it again.
output = (char*)malloc(outSize);
} else if (result) {
} else if (result < 0) {
SWARN("Regex replacement failed with result " << result << ", returning nothing.");
output = (char*)malloc(1);
*output = 0;
break;
}
}
Expand Down
5 changes: 5 additions & 0 deletions test/tests/LibStuffTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,11 @@ struct LibStuff : tpunit::TestFixture {
// And test case sensitivity (enabled)
string result3 = SREReplace("CAT", from, "dinosaur", false);
ASSERT_EQUAL(result3, expected);

// Test match groups.
string from2 = "a cat did something to a dog";
string result4 = SREReplace("cat(.*)dog", from2, "chicken$1horse");
ASSERT_EQUAL(result4, "a chicken did something to a horse");
}

void SQResultTest() {
Expand Down

0 comments on commit f7a7694

Please sign in to comment.