| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -869,8 +869,17 @@ private static ImmutableList<Segment> parseTemplate(String template) { | |||
| 869 | 869 | int pathWildCardBound = 0; | |
| 870 | 870 | ||
| 871 | 871 | for (String seg : Splitter.on('/').trimResults().split(template)) { | |
| 872 | - if (COMPLEX_DELIMITER_PATTERN.matcher(seg.substring(0, 1)).find() | ||
| 873 | - || COMPLEX_DELIMITER_PATTERN.matcher(seg.substring(seg.length() - 1)).find()) { | ||
| 872 | + // Handle _deleted-topic_ for PubSub. | ||
| 873 | + if (seg.equals("_deleted-topic_")) { | ||
| 874 | + builder.add(Segment.create(SegmentKind.LITERAL, seg)); | ||
| 875 | + continue; | ||
| 876 | + } | ||
| 877 | + | ||
| 878 | + boolean isLastSegment = (template.indexOf(seg) + seg.length()) == template.length(); | ||
| 879 | + boolean isCollectionWildcard = !isLastSegment && (seg.equals("-") || seg.equals("-}")); | ||
| 880 | + if (!isCollectionWildcard | ||
| 881 | + && (COMPLEX_DELIMITER_PATTERN.matcher(seg.substring(0, 1)).find() | ||
| 882 | + || COMPLEX_DELIMITER_PATTERN.matcher(seg.substring(seg.length() - 1)).find())) { | ||
| 874 | 883 | throw new ValidationException("parse error: invalid begin or end character in '%s'", seg); | |
| 875 | 884 | } | |
| 876 | 885 | // Disallow zero or multiple delimiters between variable names. | |
@@ -896,7 +905,7 @@ private static ImmutableList<Segment> parseTemplate(String template) { | |||
| 896 | 905 | } | |
| 897 | 906 | ||
| 898 | 907 | Matcher complexPatternDelimiterMatcher = END_SEGMENT_COMPLEX_DELIMITER_PATTERN.matcher(seg); | |
| 899 | - complexDelimiterFound = complexPatternDelimiterMatcher.find(); | ||
| 908 | + complexDelimiterFound = !isCollectionWildcard && complexPatternDelimiterMatcher.find(); | ||
| 900 | 909 | ||
| 901 | 910 | // Look for complex resource names. | |
| 902 | 911 | // Need to handle something like "{user_a}~{user_b}". | |
@@ -915,6 +924,8 @@ private static ImmutableList<Segment> parseTemplate(String template) { | |||
| 915 | 924 | throw new ValidationException( | |
| 916 | 925 | "parse error: invalid binding syntax in '%s'", template); | |
| 917 | 926 | } | |
| 927 | + } else if (seg.indexOf('-') <= 0 && isCollectionWildcard) { | ||
| 928 | + implicitWildcard = true; | ||
| 918 | 929 | } else { | |
| 919 | 930 | // Looking at something like "{name=wildcard}". | |
| 920 | 931 | varName = seg.substring(0, i).trim(); | |
@@ -957,6 +968,10 @@ private static ImmutableList<Segment> parseTemplate(String template) { | |||
| 957 | 968 | } | |
| 958 | 969 | // If the wildcard is implicit, seg will be empty. Just continue. | |
| 959 | 970 | break; | |
| 971 | + case "-": | ||
| 972 | + builder.add(Segment.WILDCARD); | ||
| 973 | + implicitWildcard = false; | ||
| 974 | + break; | ||
| 960 | 975 | default: | |
| 961 | 976 | builder.add(Segment.create(SegmentKind.LITERAL, seg)); | |
| 962 | 977 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -317,6 +317,31 @@ public void complexResourceIdMixedSeparators() { | |||
| 317 | 317 | Truth.assertThat(match.get("zone_d")).isEqualTo("europe-west2-b"); | |
| 318 | 318 | } | |
| 319 | 319 | ||
| 320 | + @Test | ||
| 321 | + public void collectionWildcardMatchingInParent() { | ||
| 322 | + PathTemplate template = PathTemplate.create("v1/publishers/-/books/{book}"); | ||
| 323 | + Map<String, String> match = | ||
| 324 | + template.match( | ||
| 325 | + "https://example.googleapis.com/v1/publishers/publisher-abc/books/blockchain_for_babies"); | ||
| 326 | + Truth.assertThat(match).isNotNull(); | ||
| 327 | + | ||
| 328 | + template = PathTemplate.create("/v1/{parent=rooms/-}/blurbs/{blurb}"); | ||
| 329 | + match = template.match("https://example.googleapis.com/v1/rooms/den/blurbs/asdf"); | ||
| 330 | + Truth.assertThat(match).isNotNull(); | ||
| 331 | + } | ||
| 332 | + | ||
| 333 | + @Test | ||
| 334 | + public void collectionWildcardMatchingInvalid() { | ||
| 335 | + thrown.expect(ValidationException.class); | ||
| 336 | + PathTemplate.create("v1/publishers/{publisher}/books/-"); | ||
| 337 | + } | ||
| 338 | + | ||
| 339 | + @Test | ||
| 340 | + public void complexResourceIdPubSubDeletedTopic() { | ||
| 341 | + PathTemplate template = PathTemplate.create("_deleted-topic_"); | ||
| 342 | + Truth.assertThat(template).isNotNull(); | ||
| 343 | + } | ||
| 344 | + | ||
| 320 | 345 | @Test | |
| 321 | 346 | public void complexResourceIdInParent() { | |
| 322 | 347 | // One parent has a complex resource ID. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments