@Test public void testUnendedParameter() throws Exception { assertThrows(IllegalPathPatternException.class, () -> { PathPattern.compile("/foo/{bar"); }); }
static PathMatcher compile(CharSequence pattern) { Objects.requireNonNull(pattern, "Parameter 'pattern' is null!"); StringBuilder regexp = new StringBuilder(pattern.length() * 2); StringBuilder canonical = new StringBuilder(pattern.length()); boolean isRegexp = false; boolean escape = false; boolean optionalSequence = false; int paramCounter = 0; Map<String, String> paramToGroupName = new HashMap<>(); CharIterator iter = new CharIterator(pattern); while (iter.hasNext()) { char ch = iter.next(); if (escape) { escape = false; } else { boolean shouldContinue = true; switch (ch) { case '\\': escape = true; break; case '[': if (optionalSequence) { throw new IllegalPathPatternException("Optional sequences cannot be nested!", pattern.toString(), iter.index() - 1); } else { optionalSequence = true; isRegexp = true; regexp.append('('); } break; case ']': if (optionalSequence) { optionalSequence = false; regexp.append(")?"); } else { shouldContinue = false; } break; case '{': isRegexp = true; String name = parseParameter(iter, regexp, paramCounter); if (name.length() > 0) { paramToGroupName.put(name, PARAM_PREFIX + paramCounter); paramCounter++; } break; default: shouldContinue = false; } if (shouldContinue) { continue; } } escapeIfNeeded(ch, regexp); canonical.append(ch); } if (optionalSequence) { throw new IllegalPathPatternException("Missing end of a optional sequence (']' character)!", pattern.toString(), iter.index() - 1); } try { if (isRegexp) { return new RegexpPathMatcher(regexp.toString(), paramToGroupName); } else { return new CanonicalPathMatcher(canonical.toString()); } } catch (RuntimeException e) { throw new IllegalPathPatternException("Cannot parse generated regular expression!", pattern.toString(), 0); } }
PathPattern { static PathMatcher compile(CharSequence pattern) { Objects.requireNonNull(pattern, "Parameter 'pattern' is null!"); StringBuilder regexp = new StringBuilder(pattern.length() * 2); StringBuilder canonical = new StringBuilder(pattern.length()); boolean isRegexp = false; boolean escape = false; boolean optionalSequence = false; int paramCounter = 0; Map<String, String> paramToGroupName = new HashMap<>(); CharIterator iter = new CharIterator(pattern); while (iter.hasNext()) { char ch = iter.next(); if (escape) { escape = false; } else { boolean shouldContinue = true; switch (ch) { case '\\': escape = true; break; case '[': if (optionalSequence) { throw new IllegalPathPatternException("Optional sequences cannot be nested!", pattern.toString(), iter.index() - 1); } else { optionalSequence = true; isRegexp = true; regexp.append('('); } break; case ']': if (optionalSequence) { optionalSequence = false; regexp.append(")?"); } else { shouldContinue = false; } break; case '{': isRegexp = true; String name = parseParameter(iter, regexp, paramCounter); if (name.length() > 0) { paramToGroupName.put(name, PARAM_PREFIX + paramCounter); paramCounter++; } break; default: shouldContinue = false; } if (shouldContinue) { continue; } } escapeIfNeeded(ch, regexp); canonical.append(ch); } if (optionalSequence) { throw new IllegalPathPatternException("Missing end of a optional sequence (']' character)!", pattern.toString(), iter.index() - 1); } try { if (isRegexp) { return new RegexpPathMatcher(regexp.toString(), paramToGroupName); } else { return new CanonicalPathMatcher(canonical.toString()); } } catch (RuntimeException e) { throw new IllegalPathPatternException("Cannot parse generated regular expression!", pattern.toString(), 0); } } }
PathPattern { static PathMatcher compile(CharSequence pattern) { Objects.requireNonNull(pattern, "Parameter 'pattern' is null!"); StringBuilder regexp = new StringBuilder(pattern.length() * 2); StringBuilder canonical = new StringBuilder(pattern.length()); boolean isRegexp = false; boolean escape = false; boolean optionalSequence = false; int paramCounter = 0; Map<String, String> paramToGroupName = new HashMap<>(); CharIterator iter = new CharIterator(pattern); while (iter.hasNext()) { char ch = iter.next(); if (escape) { escape = false; } else { boolean shouldContinue = true; switch (ch) { case '\\': escape = true; break; case '[': if (optionalSequence) { throw new IllegalPathPatternException("Optional sequences cannot be nested!", pattern.toString(), iter.index() - 1); } else { optionalSequence = true; isRegexp = true; regexp.append('('); } break; case ']': if (optionalSequence) { optionalSequence = false; regexp.append(")?"); } else { shouldContinue = false; } break; case '{': isRegexp = true; String name = parseParameter(iter, regexp, paramCounter); if (name.length() > 0) { paramToGroupName.put(name, PARAM_PREFIX + paramCounter); paramCounter++; } break; default: shouldContinue = false; } if (shouldContinue) { continue; } } escapeIfNeeded(ch, regexp); canonical.append(ch); } if (optionalSequence) { throw new IllegalPathPatternException("Missing end of a optional sequence (']' character)!", pattern.toString(), iter.index() - 1); } try { if (isRegexp) { return new RegexpPathMatcher(regexp.toString(), paramToGroupName); } else { return new CanonicalPathMatcher(canonical.toString()); } } catch (RuntimeException e) { throw new IllegalPathPatternException("Cannot parse generated regular expression!", pattern.toString(), 0); } } private  PathPattern(); }
PathPattern { static PathMatcher compile(CharSequence pattern) { Objects.requireNonNull(pattern, "Parameter 'pattern' is null!"); StringBuilder regexp = new StringBuilder(pattern.length() * 2); StringBuilder canonical = new StringBuilder(pattern.length()); boolean isRegexp = false; boolean escape = false; boolean optionalSequence = false; int paramCounter = 0; Map<String, String> paramToGroupName = new HashMap<>(); CharIterator iter = new CharIterator(pattern); while (iter.hasNext()) { char ch = iter.next(); if (escape) { escape = false; } else { boolean shouldContinue = true; switch (ch) { case '\\': escape = true; break; case '[': if (optionalSequence) { throw new IllegalPathPatternException("Optional sequences cannot be nested!", pattern.toString(), iter.index() - 1); } else { optionalSequence = true; isRegexp = true; regexp.append('('); } break; case ']': if (optionalSequence) { optionalSequence = false; regexp.append(")?"); } else { shouldContinue = false; } break; case '{': isRegexp = true; String name = parseParameter(iter, regexp, paramCounter); if (name.length() > 0) { paramToGroupName.put(name, PARAM_PREFIX + paramCounter); paramCounter++; } break; default: shouldContinue = false; } if (shouldContinue) { continue; } } escapeIfNeeded(ch, regexp); canonical.append(ch); } if (optionalSequence) { throw new IllegalPathPatternException("Missing end of a optional sequence (']' character)!", pattern.toString(), iter.index() - 1); } try { if (isRegexp) { return new RegexpPathMatcher(regexp.toString(), paramToGroupName); } else { return new CanonicalPathMatcher(canonical.toString()); } } catch (RuntimeException e) { throw new IllegalPathPatternException("Cannot parse generated regular expression!", pattern.toString(), 0); } } private  PathPattern();  }
PathPattern { static PathMatcher compile(CharSequence pattern) { Objects.requireNonNull(pattern, "Parameter 'pattern' is null!"); StringBuilder regexp = new StringBuilder(pattern.length() * 2); StringBuilder canonical = new StringBuilder(pattern.length()); boolean isRegexp = false; boolean escape = false; boolean optionalSequence = false; int paramCounter = 0; Map<String, String> paramToGroupName = new HashMap<>(); CharIterator iter = new CharIterator(pattern); while (iter.hasNext()) { char ch = iter.next(); if (escape) { escape = false; } else { boolean shouldContinue = true; switch (ch) { case '\\': escape = true; break; case '[': if (optionalSequence) { throw new IllegalPathPatternException("Optional sequences cannot be nested!", pattern.toString(), iter.index() - 1); } else { optionalSequence = true; isRegexp = true; regexp.append('('); } break; case ']': if (optionalSequence) { optionalSequence = false; regexp.append(")?"); } else { shouldContinue = false; } break; case '{': isRegexp = true; String name = parseParameter(iter, regexp, paramCounter); if (name.length() > 0) { paramToGroupName.put(name, PARAM_PREFIX + paramCounter); paramCounter++; } break; default: shouldContinue = false; } if (shouldContinue) { continue; } } escapeIfNeeded(ch, regexp); canonical.append(ch); } if (optionalSequence) { throw new IllegalPathPatternException("Missing end of a optional sequence (']' character)!", pattern.toString(), iter.index() - 1); } try { if (isRegexp) { return new RegexpPathMatcher(regexp.toString(), paramToGroupName); } else { return new CanonicalPathMatcher(canonical.toString()); } } catch (RuntimeException e) { throw new IllegalPathPatternException("Cannot parse generated regular expression!", pattern.toString(), 0); } } private  PathPattern();   }