Fixing the iso format for regex patterns; fixes gh-1296
This commit is contained in:
@@ -62,7 +62,7 @@ class RegexPatterns {
|
||||
protected static final Pattern NON_EMPTY = Pattern.compile(/[\S\s]+/)
|
||||
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)/)
|
||||
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{1,6})?(Z|[+-][01]\d:[0-5]\d)/)
|
||||
|
||||
protected static Pattern anyOf(String... values) {
|
||||
return Pattern.compile(values.collect({ "^$it\$" }).join("|"))
|
||||
|
||||
@@ -313,13 +313,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]"() {
|
||||
|
||||
Reference in New Issue
Block a user