Enhance DockerReferenceUtility to handle invalid characters#1821
Merged
Conversation
…e tests for unresolved variables
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request improves Docker image reference handling in DockerReferenceUtility by treating additional templating-token forms as “unresolved” (so they’re skipped) and by pre-validating references for clearly invalid characters, with consistent warning logs to aid troubleshooting.
Changes:
- Recognize
#token#and!token!patterns as unresolved template tokens when parsing Docker image references. - Add a fast invalid-character pre-check (
ValidReferenceChars+GetInvalidReferenceCharacters) and log warnings for skipped/invalid references. - Expand unit tests to cover the new templating-token formats and to assert warnings are emitted for skipped/invalid references.
Show a summary per file
| File | Description |
|---|---|
| src/Microsoft.ComponentDetection.Common/DockerReference/DockerReferenceUtility.cs | Adds additional templating-token detection, invalid-character detection, and warning logging to make parsing failures more diagnosable. |
| test/Microsoft.ComponentDetection.Common.Tests/DockerReferenceUtilityTests.cs | Adds/updates tests for #...# / !...! token handling and warning logging behavior. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 2
grvillic
approved these changes
Jun 5, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
grvillic
approved these changes
Jun 6, 2026
|
👋 Hi! It looks like you modified some files in the
If none of the above scenarios apply, feel free to ignore this comment 🙂 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request enhances the robustness and clarity of Docker image reference parsing by improving detection and handling of unresolved template tokens and invalid characters. It introduces stricter validation, ensures that all skipped or invalid references are logged as warnings, and expands test coverage for these scenarios.
Parsing and Validation Improvements:
#or!(e.g.,#imageTag#,!imageTag!) as unresolved template variables, ensuring these are skipped rather than misreported as invalid references [1] [2].ValidReferenceCharsset and a newGetInvalidReferenceCharactershelper to detect and report any characters not allowed by the Docker reference grammar, such as stray#or!not in a template token [1] [2].TryParseImageReferenceto log a warning and returnnullfor references with unresolved variables or invalid characters, making failures more visible in logs [1] [2].Testing Enhancements:
#...#,!...!) and to verify that warnings are logged for all skipped or invalid references, including those with stray invalid characters [1] [2] [3].These changes make Docker reference parsing more predictable and debuggable, especially when dealing with templated or malformed references.