Fixing the iso format for regex patterns; fixes gh-1296

This commit is contained in:
Marcin Grzejszczak
2019-12-31 09:33:11 +01:00
parent ba9f219bd7
commit 0a7730ef16
2 changed files with 18 additions and 8 deletions

View File

@@ -85,7 +85,7 @@ public final class RegexPatterns {
protected static final Pattern NON_BLANK = Pattern.compile("^\\s*\\S[\\S\\s]*");
protected static final Pattern ISO8601_WITH_OFFSET = Pattern.compile(
"([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\\.\\d{3})?(Z|[+-][01]\\d:[0-5]\\d)");
"([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\\.\\d{1,6})?(Z|[+-][01]\\d:[0-5]\\d)");
protected static Pattern anyOf(String... values) {
return Pattern.compile(Arrays.stream(values).map(it -> '^' + it + '$')

View File

@@ -311,13 +311,23 @@ class RegexPatternsSpec extends Specification {
expect:
shouldMatch == RegexPatterns.iso8601WithOffset().matcher(textToMatch).matches()
where:
textToMatch || shouldMatch
'2014-03-01T12:23:45Z' || true
'2014-03-01T12:23:45+01:00' || true
'2014-03-01T12:23:45.123Z' || true
'2014-03-01T12:23:45.123+01:00' || true
'2014-03-01T12:23:45' || false
'2014-03-01T12:23:45.123' || false
textToMatch || shouldMatch
'2014-03-01T12:23:45Z' || true
'2014-03-01T12:23:45+01:00' || true
'2014-03-01T12:23:45.1Z' || true
'2014-03-01T12:23:45.12Z' || true
'2014-03-01T12:23:45.123Z' || true
'2014-03-01T12:23:45.1234Z' || true
'2014-03-01T12:23:45.12345Z' || true
'2014-03-01T12:23:45.123456Z' || true
'2014-03-01T12:23:45.1+01:00' || true
'2014-03-01T12:23:45.12+01:00' || true
'2014-03-01T12:23:45.123+01:00' || true
'2014-03-01T12:23:45.1234+01:00' || true
'2014-03-01T12:23:45.12345+01:00' || true
'2014-03-01T12:23:45.123456+01:00' || true
'2014-03-01T12:23:45' || false
'2014-03-01T12:23:45.123' || false
}
def "should generate a regex for a non blank string [#textToMatch] that should match [#shouldMatch]"() {