Skip to content

Commit

Permalink
Fix NULLs in re_match/re_match_all returns (#8069)
Browse files Browse the repository at this point in the history
Replace the NULLs in the result arrays with empty strings.
Fixes #8062.
  • Loading branch information
msullivan committed Dec 20, 2024
1 parent cb548a2 commit a108352
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions edb/lib/std/30-regexpfuncs.edgeql
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ std::re_match(pattern: std::str, str: std::str) -> array<std::str>
'Find the first regular expression match in a string.';
SET volatility := 'Immutable';
USING SQL $$
SELECT regexp_matches("str", "pattern");
SELECT array_replace(regexp_matches("str", "pattern"), NULL, '');
$$;
};

Expand All @@ -39,7 +39,7 @@ std::re_match_all(pattern: std::str, str: std::str) -> SET OF array<std::str>
'Find all regular expression matches in a string.';
SET volatility := 'Immutable';
USING SQL $$
SELECT regexp_matches("str", "pattern", 'g');
SELECT array_replace(regexp_matches("str", "pattern", 'g'), NULL, '');
$$;
};

Expand Down
18 changes: 18 additions & 0 deletions edb/pgsql/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,22 @@ def _setup_patches(patches: list[tuple[str, str]]) -> list[tuple[str, str]]:
};
}
'''),
# === 5.8
('edgeql', '''
ALTER FUNCTION
std::re_match(pattern: std::str, str: std::str)
{
USING SQL $$
SELECT array_replace(regexp_matches("str", "pattern"), NULL, '');
$$;
};
ALTER FUNCTION
std::re_match_all(pattern: std::str, str: std::str)
{
USING SQL $$
SELECT array_replace(regexp_matches("str", "pattern", 'g'), NULL, '');
$$;
};
'''),

])
20 changes: 20 additions & 0 deletions tests/test_edgeql_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,16 @@ async def test_edgeql_functions_re_match_01(self):
[['Ab'], ['a']],
)

await self.assert_query_result(
r'''
select re_match(
r"(foo)?bar",
'barbar',
)
''',
[[""]],
)

async def test_edgeql_functions_re_match_02(self):
await self.assert_query_result(
r'''
Expand Down Expand Up @@ -1135,6 +1145,16 @@ async def test_edgeql_functions_re_match_all_01(self):
[['Ab'], ['a'], ['a'], ['aB'], ['ab']],
)

await self.assert_query_result(
r'''
select re_match_all(
r"(foo)?bar",
'barbar',
)
''',
[[""], [""]],
)

async def test_edgeql_functions_re_test_01(self):
await self.assert_query_result(
r'''SELECT re_test('ac', 'AbabaB');''',
Expand Down

0 comments on commit a108352

Please sign in to comment.