Encapsulate regexes in a non-capturing group 61/68461/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 20 Feb 2018 18:12:19 +0000 (19:12 +0100)
committerRobert Varga <nite@hq.sk>
Sun, 25 Feb 2018 18:53:51 +0000 (18:53 +0000)
Regular expressions are pesky, nwo we are being bitten by branches.
Let's just encapsulate the internal pattern into a non-capturing
group and be done with it.

JIRA: YANGTOOLS-798
Change-Id: If3b3b2fb35ecd336bc23fd7acaf29efa48eb9b74
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 42b62f098cbabbc286c3a506494c5e280f6c365b)

13 files changed:
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/StringPatternCheckingCodecTest.java
yang/yang-model-export/src/test/resources/bugs/bug2444/yin/modifier-yang1@1970-01-01.yin
yang/yang-model-export/src/test/resources/bugs/bug2444/yin/modifier@1970-01-01.yin
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RegexUtils.java
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/Bug4079Test.java
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/Bug5410Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Bug5410Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4623Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5396Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6180Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveStatementTypeTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TypesResolutionTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java

index 19e53794c80a7538deb671047b650bad41d5cdc4..ce836b9e6f41f67f1f3799ef0d19eb6abf342ab7 100644 (file)
@@ -65,8 +65,8 @@ public class StringPatternCheckingCodecTest {
             codec.deserialize("abcd");
             fail("Exception should have been thrown.");
         } catch (final IllegalArgumentException ex) {
-            LOG.debug("IllegalArgumentException was thrown as expected: {}", ex);
-            assertTrue(ex.getMessage().contains("Supplied value does not match the regular expression ^[A-Z]+$. [abcd]"));
+            LOG.debug("IllegalArgumentException was thrown as expected", ex);
+            assertEquals("Supplied value does not match the regular expression ^(?:[A-Z]+)$. [abcd]", ex.getMessage());
         }
     }
 }
index 55b167b7be2727b715af62b41046d1b6a216440a..26b058ce6d3651a417fad530018900cde88b1360 100644 (file)
@@ -16,7 +16,7 @@
             <pattern value=".*">
                 <error-message>
                     <value>Supplied value does not match the regular
-                        expression ^.*$.</value>
+                        expression ^(?:.*)$.</value>
                 </error-message>
                 <error-app-tag value="invalid-regular-expression"></error-app-tag>
             </pattern>
@@ -25,4 +25,4 @@
         <mandatory value="false"></mandatory>
         <status value="current"></status>
     </leaf>
-</module>
\ No newline at end of file
+</module>
index d31a2e837b1e886e1109ae8c7c82886256f96215..bd4cff2be4af3eaf13d7bee4e5671c267b6e260d 100644 (file)
@@ -16,7 +16,7 @@
             <pattern value=".*">
                 <error-message>
                     <value>Supplied value does not match the regular
-                        expression ^.*$.</value>
+                        expression ^(?:.*)$.</value>
                 </error-message>
                 <error-app-tag value="invalid-regular-expression"></error-app-tag>
                 <modifier value="invert-match"></modifier>
@@ -26,4 +26,4 @@
         <mandatory value="false"></mandatory>
         <status value="current"></status>
     </leaf>
-</module>
\ No newline at end of file
+</module>
index 0991750e6ca55ec6f282c582cf8196f762f439c5..7aab1eaf94658cab1e118d2a421788607d6558be 100644 (file)
@@ -246,7 +246,8 @@ public final class RegexUtils {
      * @return Java-compatible regex
      */
     public static String getJavaRegexFromXSD(final String xsdRegex) {
-        return "^" + fixUnicodeScriptPattern(escapeChars(xsdRegex)) + '$';
+        // Note: we are using a non-capturing group to deal with internal structure issues, like branches and similar.
+        return "^(?:" + fixUnicodeScriptPattern(escapeChars(xsdRegex)) + ")$";
     }
 
     /*
index 5333c9882b4eae80d6c1b9a03f19803264c4ee45..28db4a52b6b45d054e872f42d11dae9180c399e2 100644 (file)
@@ -8,8 +8,11 @@
 package org.opendaylight.yangtools.yang.model.util;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
+import java.util.function.Predicate;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
 import org.junit.Test;
@@ -19,96 +22,96 @@ public class Bug4079Test {
     @Test
     public void testValidPatternFix() {
         String fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsArrows})*+");
-        assertEquals("^(\\p{InArrows})*+$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{InArrows})*+)$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsDingbats})++");
-        assertEquals("^(\\p{InDingbats})++$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{InDingbats})++)$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsSpecials})?+");
-        assertEquals("^(\\p{InSpecials})?+$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{InSpecials})?+)$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsBatak}){4}+");
-        assertEquals("^(\\p{IsBatak}){4}+$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{IsBatak}){4}+)$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsLatin}){4,6}+");
-        assertEquals("^(\\p{IsLatin}){4,6}+$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{IsLatin}){4,6}+)$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsTibetan}){4,}+");
-        assertEquals("^(\\p{IsTibetan}){4,}+$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{IsTibetan}){4,}+)$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsAlphabetic}){4}?");
-        assertEquals("^(\\p{IsAlphabetic}){4}?$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{IsAlphabetic}){4}?)$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsLowercase}){4,6}?");
-        assertEquals("^(\\p{IsLowercase}){4,6}?$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{IsLowercase}){4,6}?)$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsUppercase}){4,}?");
-        assertEquals("^(\\p{IsUppercase}){4,}?$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{IsUppercase}){4,}?)$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsBasicLatin}|\\p{IsLatin-1Supplement})*");
-        assertEquals("^(\\p{InBasicLatin}|\\p{InLatin-1Supplement})*$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{InBasicLatin}|\\p{InLatin-1Supplement})*)$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{InBasicLatin}|\\p{InLatin-1Supplement})+");
-        assertEquals("^(\\p{InBasicLatin}|\\p{InLatin-1Supplement})+$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{InBasicLatin}|\\p{InLatin-1Supplement})+)$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsBasicLatin}|\\p{InLatin-1Supplement})?");
-        assertEquals("^(\\p{InBasicLatin}|\\p{InLatin-1Supplement})?$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{InBasicLatin}|\\p{InLatin-1Supplement})?)$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{InBasicLatin}|\\p{IsLatin-1Supplement}){4}");
-        assertEquals("^(\\p{InBasicLatin}|\\p{InLatin-1Supplement}){4}$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{InBasicLatin}|\\p{InLatin-1Supplement}){4})$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsLatin}|\\p{IsArmenian}){2,4}");
-        assertEquals("^(\\p{IsLatin}|\\p{IsArmenian}){2,4}$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{IsLatin}|\\p{IsArmenian}){2,4})$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsLatin}|\\p{IsBasicLatin}){2,}");
-        assertEquals("^(\\p{IsLatin}|\\p{InBasicLatin}){2,}$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{IsLatin}|\\p{InBasicLatin}){2,})$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsBasicLatin}|\\p{IsLatin})*?");
-        assertEquals("^(\\p{InBasicLatin}|\\p{IsLatin})*?$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{InBasicLatin}|\\p{IsLatin})*?)$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD(
                 "(\\p{IsBasicLatin}|\\p{IsLatin-1Supplement}|\\p{IsArrows})+?");
-        assertEquals("^(\\p{InBasicLatin}|\\p{InLatin-1Supplement}|\\p{InArrows})+?$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{InBasicLatin}|\\p{InLatin-1Supplement}|\\p{InArrows})+?)$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD(
                 "(\\p{InBasicLatin}|\\p{IsLatin-1Supplement}|\\p{IsLatin})??");
-        assertEquals("^(\\p{InBasicLatin}|\\p{InLatin-1Supplement}|\\p{IsLatin})??$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{InBasicLatin}|\\p{InLatin-1Supplement}|\\p{IsLatin})??)$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\\\\\p{IsBasicLatin})*+");
-        assertEquals("^(\\\\\\p{InBasicLatin})*+$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\\\\\p{InBasicLatin})*+)$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\\\\\\\\\p{IsBasicLatin})*+");
-        assertEquals("^(\\\\\\\\\\p{InBasicLatin})*+$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\\\\\\\\\p{InBasicLatin})*+)$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
 
         fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\\\\\\\\\\\\\p{IsBasicLatin})*+");
-        assertEquals("^(\\\\\\\\\\\\\\p{InBasicLatin})*+$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\\\\\\\\\\\\\p{InBasicLatin})*+)$", fixedUnicodeScriptPattern);
         assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
     }
 
     @Test(expected = PatternSyntaxException.class)
     public void testInvalidPattern() {
         String fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\\\p{IsBasicLatin})*+");
-        assertEquals("^(\\\\p{IsBasicLatin})*+$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\\\p{IsBasicLatin})*+)$", fixedUnicodeScriptPattern);
         // should throw exception
         Pattern.compile(fixedUnicodeScriptPattern);
     }
@@ -117,7 +120,7 @@ public class Bug4079Test {
     public void testInvalidPattern2() {
         String fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD(
             "(\\p{IsSpecials}|\\\\\\\\p{IsBasicLatin})*+");
-        assertEquals("^(\\p{InSpecials}|\\\\\\\\p{IsBasicLatin})*+$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\p{InSpecials}|\\\\\\\\p{IsBasicLatin})*+)$", fixedUnicodeScriptPattern);
         // should throw exception
         Pattern.compile(fixedUnicodeScriptPattern);
     }
@@ -126,8 +129,21 @@ public class Bug4079Test {
     public void testInvalidPattern3() {
         String fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD(
             "(\\\\\\\\\\\\p{IsBasicLatin}|\\p{IsTags})*+");
-        assertEquals("^(\\\\\\\\\\\\p{IsBasicLatin}|\\p{IsTags})*+$", fixedUnicodeScriptPattern);
+        assertEquals("^(?:(\\\\\\\\\\\\p{IsBasicLatin}|\\p{IsTags})*+)$", fixedUnicodeScriptPattern);
         // should throw exception
         Pattern.compile(fixedUnicodeScriptPattern);
     }
+
+    @Test
+    public void testCorrectBranches() {
+        String str = RegexUtils.getJavaRegexFromXSD("a|bb");
+        assertEquals("^(?:a|bb)$", str);
+        Predicate<String> pred = Pattern.compile(str).asPredicate();
+
+        assertTrue(pred.test("a"));
+        assertTrue(pred.test("bb"));
+        assertFalse(pred.test("ab"));
+        assertFalse(pred.test("abb"));
+        assertFalse(pred.test("ac"));
+    }
 }
index 41daafa856d05d4f579bfa9a6033e6ed6d2d7394..0e997093796c9b3716bdc1f4ff3020e0ef3b7b1b 100644 (file)
@@ -118,26 +118,29 @@ public class Bug5410Test {
 
     @Test
     public void testJavaRegexFromXSD() {
-        testPattern("^[^:]+$", "^\\^[^:]+\\$$", ImmutableList.of("^a$", "^abc$"),
+        testPattern("^[^:]+$", "^(?:\\^[^:]+\\$)$", ImmutableList.of("^a$", "^abc$"),
                 ImmutableList.of("abc$", "^abc", "^a:bc$"));
-        testPattern("^[$^]$", "^\\^[$^]\\$$", ImmutableList.of("^^$", "^$$"), ImmutableList.of("^^", "^$", "$^", "$$"));
-        testPattern("[$-%]+", "^[$-%]+$", ImmutableList.of("$", "%", "%$"), ImmutableList.of("$-", "$-%", "-", "^"));
-        testPattern("[$-&]+", "^[$-&]+$", ImmutableList.of("$", "%&", "%$", "$%&"), ImmutableList.of("#", "$-&", "'"));
-
-        testPattern("[a-z&&[^m-p]]+", "^[a-z&&[^m-p]]+$", ImmutableList.of("a", "z", "az"),
+        testPattern("^[$^]$", "^(?:\\^[$^]\\$)$", ImmutableList.of("^^$", "^$$"),
+            ImmutableList.of("^^", "^$", "$^", "$$"));
+        testPattern("[$-%]+", "^(?:[$-%]+)$", ImmutableList.of("$", "%", "%$"),
+            ImmutableList.of("$-", "$-%", "-", "^"));
+        testPattern("[$-&]+", "^(?:[$-&]+)$", ImmutableList.of("$", "%&", "%$", "$%&"),
+            ImmutableList.of("#", "$-&", "'"));
+
+        testPattern("[a-z&&[^m-p]]+", "^(?:[a-z&&[^m-p]]+)$", ImmutableList.of("a", "z", "az"),
                 ImmutableList.of("m", "anz", "o"));
-        testPattern("^[\\[-b&&[^^-a]]+$", "^\\^[\\[-b&&[^^-a]]+\\$$", ImmutableList.of("^[$", "^\\$", "^]$", "^b$"),
+        testPattern("^[\\[-b&&[^^-a]]+$", "^(?:\\^[\\[-b&&[^^-a]]+\\$)$", ImmutableList.of("^[$", "^\\$", "^]$", "^b$"),
                 ImmutableList.of("^a$", "^^$", "^_$"));
 
-        testPattern("[^^-~&&[^$-^]]", "^[^^-~&&[^$-^]]$", ImmutableList.of("!", "\"", "#"),
+        testPattern("[^^-~&&[^$-^]]", "^(?:[^^-~&&[^$-^]])$", ImmutableList.of("!", "\"", "#"),
                 ImmutableList.of("a", "A", "z", "Z", "$", "%", "^", "}"));
-        testPattern("\\\\\\[^[^^-~&&[^$-^]]", "^\\\\\\[\\^[^^-~&&[^$-^]]$",
+        testPattern("\\\\\\[^[^^-~&&[^$-^]]", "^(?:\\\\\\[\\^[^^-~&&[^$-^]])$",
                 ImmutableList.of("\\[^ ", "\\[^!", "\\[^\"", "\\[^#"),
                 ImmutableList.of("\\[^a", "\\[^A", "\\[^z", "\\[^Z", "\\[^$", "\\[^%", "\\[^^", "\\[^}"));
-        testPattern("^\\[^\\\\[^^-b&&[^\\[-\\]]]\\]^", "^\\^\\[\\^\\\\[^^-b&&[^\\[-\\]]]\\]\\^$",
+        testPattern("^\\[^\\\\[^^-b&&[^\\[-\\]]]\\]^", "^(?:\\^\\[\\^\\\\[^^-b&&[^\\[-\\]]]\\]\\^)$",
                 ImmutableList.of("^[^\\c]^", "^[^\\Z]^"),
                 ImmutableList.of("^[^\\[]^", "^[^\\\\]^", "^[^\\]]^", "^[^\\^]^", "^[^\\_]^", "^[^\\b]^"));
-        testPattern("[\\^]$", "^[\\^]\\$$", ImmutableList.of("^$"),
+        testPattern("[\\^]$", "^(?:[\\^]\\$)$", ImmutableList.of("^$"),
                 ImmutableList.of("^", "$", "$^", "\\", "\\^", "\\^\\", "\\^\\$"));
     }
 
@@ -160,7 +163,7 @@ public class Bug5410Test {
     }
 
     private static void testPattern(final String xsdRegex, final String unanchoredJavaRegex) {
-        testPattern(xsdRegex, '^' + unanchoredJavaRegex + '$', ImmutableList.of(), ImmutableList.of());
+        testPattern(xsdRegex, "^(?:" + unanchoredJavaRegex + ")$", ImmutableList.of(), ImmutableList.of());
     }
 
     private static void testPattern(final String javaRegex, final List<String> positiveMatches,
index 9f02e00efab9e6708e3caba7b0ca6f6a7fce7d03..2195142d6fffece157a6c3da42b8d8303ba27c5d 100644 (file)
@@ -40,7 +40,9 @@ public class Bug5410Test {
         assertEquals(expectedYangRegex, rawRegex);
 
         final String javaRegexFromYang = pattern.getRegularExpression();
-        final String expectedJavaRegex = "^\\$0\\$.*|\\$1\\$[a-zA-Z0-9./]{1,8}\\$[a-zA-Z0-9./]{22}|\\$5\\$(rounds=\\d+\\$)?[a-zA-Z0-9./]{1,16}\\$[a-zA-Z0-9./]{43}|\\$6\\$(rounds=\\d+\\$)?[a-zA-Z0-9./]{1,16}\\$[a-zA-Z0-9./]{86}$";
+        final String expectedJavaRegex = "^(?:\\$0\\$.*|\\$1\\$[a-zA-Z0-9./]{1,8}\\$[a-zA-Z0-9./]{22}|\\$5\\$"
+                + "(rounds=\\d+\\$)?[a-zA-Z0-9./]{1,16}\\$[a-zA-Z0-9./]{43}|\\$6\\$(rounds=\\d+\\$)?"
+                + "[a-zA-Z0-9./]{1,16}\\$[a-zA-Z0-9./]{86})$";
         assertEquals(expectedJavaRegex, javaRegexFromYang);
 
         final String value = "$6$AnrKGc0V$B/0/A.pWg4HrrA6YiEJOtFGibQ9Fmm5.4rI/00gEz3QeB7joSxBU3YtbHDm6NSkS1dKTQy3BWhwKKDS8nB5S//";
index 04fef165b59c4f7184d4c938d2cbe1706c64b9d2..7ccda315e83576ba26d0137a40464aabc00f4d26 100644 (file)
@@ -61,7 +61,7 @@ public class Bug4623Test {
         Assert.assertEquals(lengthConstraint.getMax(), Integer.valueOf(10));
 
         final PatternConstraint patternConstraint = patternConstraints.get(0);
-        Assert.assertEquals(patternConstraint.getRegularExpression(), "^[0-9a-fA-F]$");
+        Assert.assertEquals(patternConstraint.getRegularExpression(), "^(?:[0-9a-fA-F])$");
     }
 
     @Test
@@ -102,7 +102,7 @@ public class Bug4623Test {
         Assert.assertEquals(lengthConstraint.getMax(), Integer.valueOf(10));
 
         final PatternConstraint patternConstraint = patternConstraints.get(0);
-        Assert.assertEquals(patternConstraint.getRegularExpression(), "^[0-9a-fA-F]$");
+        Assert.assertEquals(patternConstraint.getRegularExpression(), "^(?:[0-9a-fA-F])$");
     }
 
     @Test
@@ -143,6 +143,6 @@ public class Bug4623Test {
         Assert.assertEquals(lengthConstraint.getMax(), Integer.valueOf(10));
 
         final PatternConstraint patternConstraint = patternConstraints.get(0);
-        Assert.assertEquals(patternConstraint.getRegularExpression(), "^[0-9a-fA-F]$");
+        Assert.assertEquals(patternConstraint.getRegularExpression(), "^(?:[0-9a-fA-F])$");
     }
-}
\ No newline at end of file
+}
index 816aa58bb859713c7be1160aafc8ebaee24e2b85..08da5c894793b00e40aae8ec2b6385a646d527ea 100644 (file)
@@ -82,10 +82,10 @@ public class Bug5396Test {
         PatternConstraint patternConstraint2 = patternConstraints2.get(0);
         PatternConstraint patternConstraint3 = patternConstraints3.get(0);
 
-        assertEquals("^dp[0-9]+o[0-9]+(d[0-9]+)?$", patternConstraint0.getRegularExpression());
-        assertEquals("^dp[0-9]+s[0-9]+(f[0-9]+)?(d[0-9]+)?$", patternConstraint1.getRegularExpression());
-        assertEquals("^dp[0-9]+(P[0-9]+)?p[0-9]{1,3}s[0-9]{1,3}(f[0-9]+)?(d[0-9]+)?$",
+        assertEquals("^(?:dp[0-9]+o[0-9]+(d[0-9]+)?)$", patternConstraint0.getRegularExpression());
+        assertEquals("^(?:dp[0-9]+s[0-9]+(f[0-9]+)?(d[0-9]+)?)$", patternConstraint1.getRegularExpression());
+        assertEquals("^(?:dp[0-9]+(P[0-9]+)?p[0-9]{1,3}s[0-9]{1,3}(f[0-9]+)?(d[0-9]+)?)$",
                 patternConstraint2.getRegularExpression());
-        assertEquals("^dp[0-9]+p[0-9]+p[0-9]+$", patternConstraint3.getRegularExpression());
+        assertEquals("^(?:dp[0-9]+p[0-9]+p[0-9]+)$", patternConstraint3.getRegularExpression());
     }
 }
index 05f2288f121273e6a2da3fc6f4c2305d9cf31dc4..ac46c854b35f597f75663291026f6043a3be14d0 100644 (file)
@@ -80,7 +80,7 @@ public class Bug6180Test {
         final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints();
         assertEquals(1, patternConstraints.size());
         final PatternConstraint pattern = patternConstraints.iterator().next();
-        assertEquals("^\".*\"$", pattern.getRegularExpression());
+        assertEquals("^(?:\".*\")$", pattern.getRegularExpression());
         assertTrue(Pattern.compile(pattern.getRegularExpression()).matcher("\"enclosed string in quotes\"").matches());
     }
 
@@ -98,7 +98,7 @@ public class Bug6180Test {
         final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints();
         assertEquals(1, patternConstraints.size());
         final PatternConstraint pattern = patternConstraints.iterator().next();
-        assertEquals("^'.*'$", pattern.getRegularExpression());
+        assertEquals("^(?:'.*')$", pattern.getRegularExpression());
         assertTrue(Pattern.compile(pattern.getRegularExpression()).matcher("'enclosed string in quotes'").matches());
     }
-}
\ No newline at end of file
+}
index b60f652e0ff898a10868da43d4af14708583dae3..721d269e6dc8166700828a63c4934270eff0307d 100644 (file)
@@ -423,10 +423,10 @@ public class EffectiveStatementTypeTest {
         final PatternConstraintEffectiveImpl patternConstraintSecond = (PatternConstraintEffectiveImpl) ((StringTypeDefinition) currentLeaf
                 .getType()).getPatternConstraints().get(0);
 
-        assertEquals("^[0-9a-fA-F]*$", patternConstraint.getRegularExpression());
+        assertEquals("^(?:[0-9a-fA-F]*)$", patternConstraint.getRegularExpression());
         assertNull(patternConstraint.getReference());
         assertNull(patternConstraint.getDescription());
-        assertEquals("Supplied value does not match the regular expression ^[0-9a-fA-F]*$.", patternConstraint.getErrorMessage());
+        assertEquals("Supplied value does not match the regular expression ^(?:[0-9a-fA-F]*)$.", patternConstraint.getErrorMessage());
         assertEquals("invalid-regular-expression", patternConstraint.getErrorAppTag());
         assertNotNull(patternConstraint.toString());
         assertNotNull(patternConstraint.hashCode());
index 49dbba72b6c8d882cd47c46e7507b295aed8f052..60a8b72cc32c10cf927ab8a0ed10d2c602dea114 100644 (file)
@@ -130,20 +130,20 @@ public class TypesResolutionTest {
 
         StringTypeDefinition ipv4 = (StringTypeDefinition) unionTypes.get(0);
         assertNotNull(ipv4.getBaseType());
-        String expectedPattern = "^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}"
-                + "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" + "(%[\\p{N}\\p{L}]+)?$";
+        String expectedPattern = "^(?:(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}"
+                + "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" + "(%[\\p{N}\\p{L}]+)?)$";
         assertEquals(expectedPattern, ipv4.getPatternConstraints().get(0).getRegularExpression());
 
         StringTypeDefinition ipv6 = (StringTypeDefinition) unionTypes.get(1);
         assertNotNull(ipv6.getBaseType());
         List<PatternConstraint> ipv6Patterns = ipv6.getPatternConstraints();
-        expectedPattern = "^((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}"
+        expectedPattern = "^(?:((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}"
                 + "((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|" + "(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}"
-                + "(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))" + "(%[\\p{N}\\p{L}]+)?$";
+                + "(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))" + "(%[\\p{N}\\p{L}]+)?)$";
         assertEquals(expectedPattern, ipv6Patterns.get(0).getRegularExpression());
 
-        expectedPattern = "^(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|" + "((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)"
-                + "(%.+)?$";
+        expectedPattern = "^(?:(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|" + "((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)"
+                + "(%.+)?)$";
         assertEquals(expectedPattern, ipv6Patterns.get(1).getRegularExpression());
     }
 
@@ -155,8 +155,8 @@ public class TypesResolutionTest {
         assertNotNull(type.getBaseType());
         List<PatternConstraint> patterns = type.getPatternConstraints();
         assertEquals(1, patterns.size());
-        String expectedPattern = "^((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*"
-                + "([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)" + "|\\.$";
+        String expectedPattern = "^(?:((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*"
+                + "([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)" + "|\\.)$";
         assertEquals(expectedPattern, patterns.get(0).getRegularExpression());
 
         List<LengthConstraint> lengths = type.getLengthConstraints();
@@ -310,7 +310,7 @@ public class TypesResolutionTest {
         List<PatternConstraint> patterns = testedType.getPatternConstraints();
         assertEquals(1, patterns.size());
         PatternConstraint pattern = patterns.get(0);
-        assertEquals("^\\d*(\\.\\d*){1,127}$", pattern.getRegularExpression());
+        assertEquals("^(?:\\d*(\\.\\d*){1,127})$", pattern.getRegularExpression());
 
         QName testedTypeQName = testedType.getQName();
         assertEquals(URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types"), testedTypeQName.getNamespace());
@@ -322,7 +322,7 @@ public class TypesResolutionTest {
         assertEquals(1, patterns.size());
 
         pattern = patterns.get(0);
-        assertEquals("^(([0-1](\\.[1-3]?[0-9]))|(2\\.(0|([1-9]\\d*))))(\\.(0|([1-9]\\d*)))*$",
+        assertEquals("^(?:(([0-1](\\.[1-3]?[0-9]))|(2\\.(0|([1-9]\\d*))))(\\.(0|([1-9]\\d*)))*)$",
                 pattern.getRegularExpression());
 
         QName testedTypeBaseQName = testedTypeBase.getQName();
index 6f0aa2189deb7c2f5da08caf5cc5bf91f28246ee..4db6ea855e61b4f4219cb19ca7b7359c622dac34 100644 (file)
@@ -244,7 +244,7 @@ public class YangParserTest {
         List<PatternConstraint> patterns = type.getPatternConstraints();
         assertEquals(1, patterns.size());
         PatternConstraint pattern = patterns.iterator().next();
-        assertEquals("^[e-z]*$", pattern.getRegularExpression());
+        assertEquals("^(?:[e-z]*)$", pattern.getRegularExpression());
         assertEquals(1, type.getLengthConstraints().size());
 
         final StringTypeDefinition baseType1 = type.getBaseType();
@@ -257,7 +257,7 @@ public class YangParserTest {
         patterns = baseType1.getPatternConstraints();
         assertEquals(1, patterns.size());
         pattern = patterns.iterator().next();
-        assertEquals("^[b-u]*$", pattern.getRegularExpression());
+        assertEquals("^(?:[b-u]*)$", pattern.getRegularExpression());
         assertEquals(1, baseType1.getLengthConstraints().size());
 
         final StringTypeDefinition baseType2 = baseType1.getBaseType();
@@ -284,7 +284,7 @@ public class YangParserTest {
         patterns = baseType3.getPatternConstraints();
         assertEquals(1, patterns.size());
         pattern = patterns.iterator().next();
-        assertEquals("^[a-k]*$", pattern.getRegularExpression());
+        assertEquals("^(?:[a-k]*)$", pattern.getRegularExpression());
         final List<LengthConstraint> baseType3Lengths = baseType3.getLengthConstraints();
         assertEquals(1, baseType3Lengths.size());
         length = baseType3Lengths.get(0);
@@ -334,7 +334,7 @@ public class YangParserTest {
         assertTrue(!patterns.isEmpty());
         assertEquals(1, patterns.size());
         final PatternConstraint pattern = patterns.iterator().next();
-        assertEquals("^[e-z]*$", pattern.getRegularExpression());
+        assertEquals("^(?:[e-z]*)$", pattern.getRegularExpression());
         assertEquals(1, type.getLengthConstraints().size());
 
         final LeafSchemaNode multiplePatternDirectStringDefLeaf = (LeafSchemaNode) foo
@@ -353,9 +353,9 @@ public class YangParserTest {
         boolean isEZPattern = false;
         boolean isADPattern = false;
         for (final PatternConstraint patternConstraint : patterns) {
-            if (patternConstraint.getRegularExpression().equals("^[e-z]*$")) {
+            if (patternConstraint.getRegularExpression().equals("^(?:[e-z]*)$")) {
                 isEZPattern = true;
-            } else if (patternConstraint.getRegularExpression().equals("^[a-d]*$")) {
+            } else if (patternConstraint.getRegularExpression().equals("^(?:[a-d]*)$")) {
                 isADPattern = true;
             }
         }
@@ -407,7 +407,7 @@ public class YangParserTest {
         final List<PatternConstraint> patterns = baseType2.getPatternConstraints();
         assertEquals(1, patterns.size());
         final PatternConstraint pattern = patterns.iterator().next();
-        assertEquals("^[a-k]*$", pattern.getRegularExpression());
+        assertEquals("^(?:[a-k]*)$", pattern.getRegularExpression());
         final List<LengthConstraint> baseType3Lengths = baseType2.getLengthConstraints();
         assertEquals(1, baseType3Lengths.size());
         length = baseType3Lengths.get(0);