Skip to content

Commit

Permalink
Merge pull request #54 from bats-core/fix/issue-53-assert_regex-deems…
Browse files Browse the repository at this point in the history
…-regex-matching-empty-string-as-invalid

assert_regex: matching empty string is not invalid regex
  • Loading branch information
martin-schulze-vireso authored Jan 6, 2023
2 parents 78fa631 + 51f5fd7 commit db015db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/assert_regex.bash
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ assert_regex() {
local -r value="${1}"
local -r pattern="${2}"

if [[ '' =~ ${pattern} ]] || (( ${?} == 2 )); then
if [[ '' =~ ${pattern} ]]; (( ${?} == 2 )); then
echo "Invalid extended regular expression: \`${pattern}'" \
| batslib_decorate 'ERROR: assert_regex' \
| fail
Expand Down
5 changes: 5 additions & 0 deletions test/assert_regex.bats
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,8 @@ Invalid extended regular expression: `[.*'
--
ERR_MSG
}

@test "assert_regex allows regex matching empty string (see #53)" {
run assert_regex any_value '.*'
assert_success
}

0 comments on commit db015db

Please sign in to comment.