Skip to content

Commit

Permalink
added check for Null JsonValue for regex matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Levell committed Feb 27, 2021
1 parent 7c1f482 commit 672e853
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fun <M : Mismatch> matchRegex(
actual: Any?,
mismatchFactory: MismatchFactory<M>
): List<M> {
val matches = safeToString(actual).matches(Regex(regex))
val matches = if (actual is JsonValue.Null) false else safeToString(actual).matches(Regex(regex))
logger.debug { "comparing ${valueOf(actual)} with regexp $regex at $path -> $matches" }
return if (matches ||
expected is List<*> && actual is List<*> ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ class MatcherExecutorSpec extends Specification {
MatcherExecutorKt.domatch(new RegexMatcher(regex), path, expected, actual, mismatchFactory).empty == mustBeEmpty

where:
expected | actual | regex || mustBeEmpty
'Harry' | 'Happy' | 'Ha[a-z]*' || true
'Harry' | null | 'Ha[a-z]*' || false
'100' | 20123 | '\\d+' || true
'100' | new JsonValue.Integer('20123'.chars) | '\\d+' || true
expected | actual | regex || mustBeEmpty
'Harry' | 'Happy' | 'Ha[a-z]*' || true
'Harry' | null | 'Ha[a-z]*' || false
'100' | 20123 | '\\d+' || true
'100' | new JsonValue.Integer('20123'.chars) | '\\d+' || true
json('"issue1316"') | JsonValue.Null.INSTANCE | '[a-x0-9]+' || false
}

@Unroll
Expand Down

0 comments on commit 672e853

Please sign in to comment.