From 630c03d02bf04a36fee1e7014120ac0c9f44d152 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Tue, 31 Dec 2019 09:36:32 +0100 Subject: [PATCH] Fixing the iso format for regex patterns; fixes gh-1296 --- .../spec/internal/RegexPatterns.groovy | 2 +- .../spec/internal/RegexPatternsSpec.groovy | 24 +++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexPatterns.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexPatterns.groovy index bb26a0d03f..a6a0a0b353 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexPatterns.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/RegexPatterns.groovy @@ -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("|")) diff --git a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/RegexPatternsSpec.groovy b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/RegexPatternsSpec.groovy index 67af92ffc9..9faeb9685a 100644 --- a/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/RegexPatternsSpec.groovy +++ b/spring-cloud-contract-spec/src/test/groovy/org/springframework/cloud/contract/spec/internal/RegexPatternsSpec.groovy @@ -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]"() {