@@ -298,7 +298,8 @@ public Set<String> vars() {
298298
299299 /**
300300 * Returns the set of resource literals. A resource literal is a literal followed by a binding.
301- * For example, projects/{project} is a literal/binding pair and projects is a resource literal.
301+ * For example, projects/{project} is a literal/binding pair and projects is a resource
302+ * literal.
302303 */
303304 public Set <String > getResourceLiterals () {
304305 Set <String > canonicalSegments = new java .util .LinkedHashSet <>();
@@ -311,7 +312,7 @@ public Set<String> getResourceLiterals() {
311312 inBinding = false ;
312313 } else if (seg .kind () == SegmentKind .LITERAL ) {
313314 String value = seg .value ();
314- if (value .matches ("^v\\ d+.*" ) || value . matches ( "^u \\ d+.* " )) { // just in case
315+ if (value .matches ("^v\\ d+[a-zA-Z0-9]*$ " )) { // just in case
315316 continue ;
316317 }
317318 if (inBinding ) {
@@ -325,16 +326,18 @@ public Set<String> getResourceLiterals() {
325326 }
326327
327328 /**
328- * Returns the canonical resource name string. A canonical resource name is extracted from the template by finding the version literal,
329- * then finding the last binding that is a literal/binding pair or named binding,
330- * and then extracting the segments between the version literal and the last binding.
331- * For examplem, projects/{project} is a literal/binding pair. {bar=projects/*/ locations /*/bars/*} is a named binding.
329+ * Returns the canonical resource name string. A canonical resource name is extracted from the
330+ * template by finding the version literal, then finding the last binding that is a
331+ * literal/binding pair or named binding, and then extracting the segments between the version
332+ * literal and the last binding.
332333 */
334+ // For example, projects/{project} is a literal/binding pair. {bar=projects/*/locations/*/bars/*}
335+ // is a named binding.
333336 public String getCanonicalResourceName (Set <String > knownResources ) {
334337 if (knownResources == null ) {
335338 return "" ;
336339 }
337-
340+
338341 int firstBindingIndex = -1 ;
339342 for (int i = 0 ; i < segments .size (); i ++) {
340343 if (segments .get (i ).kind () == SegmentKind .BINDING ) {
@@ -352,7 +355,7 @@ public String getCanonicalResourceName(Set<String> knownResources) {
352355 Segment seg = segments .get (i );
353356 if (seg .kind () == SegmentKind .LITERAL ) {
354357 String value = seg .value ();
355- if (value .matches ("^v\\ d+.*" ) || value . matches ( "^u \\ d+.* " )) {
358+ if (value .matches ("^v\\ d+[a-zA-Z0-9]*$ " )) {
356359 startIndex = i + 1 ;
357360 break ;
358361 }
@@ -373,7 +376,7 @@ public String getCanonicalResourceName(Set<String> knownResources) {
373376 } else if (seg .kind () == SegmentKind .END_BINDING ) {
374377 inBinding = false ;
375378 boolean isValidPair = false ;
376-
379+
377380 if (literalCountInBinding > 1 ) {
378381 // Named bindings are unconditionally considered pairs
379382 isValidPair = true ;
@@ -395,14 +398,14 @@ public String getCanonicalResourceName(Set<String> knownResources) {
395398 }
396399 }
397400 }
398-
401+
399402 if (isValidPair ) {
400403 lastValidEndBindingIndex = i ;
401404 }
402405 } else if (seg .kind () == SegmentKind .LITERAL ) {
403406 if (inBinding ) {
404407 String value = seg .value ();
405- if (!value .matches ("^v\\ d+.*" ) && ! value . matches ( "^u \\ d+.* " )) {
408+ if (!value .matches ("^v\\ d+[a-zA-Z0-9]*$ " )) {
406409 literalCountInBinding ++;
407410 }
408411 }
0 commit comments