@@ -28,6 +28,7 @@ namespace Microsoft.ComponentDetection.Common;
2828
2929using System ;
3030using System . Diagnostics . CodeAnalysis ;
31+ using System . Text . RegularExpressions ;
3132using Microsoft . ComponentDetection . Contracts ;
3233using Microsoft . Extensions . Logging ;
3334
@@ -39,14 +40,29 @@ public static class DockerReferenceUtility
3940 private const string LEGACYDEFAULTDOMAIN = "index.docker.io" ;
4041 private const string OFFICIALREPOSITORYNAME = "library" ;
4142
43+ // Characters that only appear in an image reference as part of an unresolved templating
44+ // token. '$', '{' and '}' cover shell / Helm / Go-template placeholders (e.g. ${VAR},
45+ // {{ .Values.tag }}); '#' covers Azure DevOps and other token-replacement placeholders
46+ // (e.g. #imageTag#) and is never valid in a resolved docker reference.
47+ private static readonly char [ ] TemplateDelimiters = [ '$' , '{' , '}' , '#' ] ;
48+
49+ // Matches token-replacement placeholders that wrap an identifier in double underscores,
50+ // e.g. __IMAGE_TAG__ or __MCR_ENDPOINT__. Without this they parse as an uppercase repository
51+ // name and surface as a noisy parse failure instead of being skipped as a templated value.
52+ private static readonly Regex DoubleUnderscoreTokenRegex = new ( @"__\w+__" ) ;
53+
4254 /// <summary>
43- /// Returns true if the reference contains unresolved variable placeholders (e.g., ${VAR}, {{ .Values.tag }}).
44- /// Such references should be skipped before calling <see cref="ParseFamiliarName"/> or <see cref="ParseQualifiedName"/>.
55+ /// Returns true if the reference contains unresolved variable or templating placeholders,
56+ /// e.g. <c>${VAR}</c>, <c>{{ .Values.tag }}</c>, <c>#imageTag#</c>, or <c>__IMAGE_TAG__</c>.
57+ /// Such references are not real, resolvable images, so they should be skipped before calling
58+ /// <see cref="ParseFamiliarName"/> or <see cref="ParseQualifiedName"/> and treated as
59+ /// unresolved values rather than reported as parse failures.
4560 /// </summary>
4661 /// <param name="reference">The image reference string to check.</param>
4762 /// <returns><c>true</c> if the reference contains variable placeholder characters; otherwise <c>false</c>.</returns>
4863 public static bool HasUnresolvedVariables ( string reference ) =>
49- reference . IndexOfAny ( [ '$' , '{' , '}' ] ) >= 0 ;
64+ reference . IndexOfAny ( TemplateDelimiters ) >= 0 ||
65+ DoubleUnderscoreTokenRegex . IsMatch ( reference ) ;
5066
5167 /// <summary>
5268 /// Attempts to parse an image reference string into a <see cref="DockerReference"/>.
0 commit comments