fix: expand commit hash regex to support SHA-256 (64-char) hashes#4347
Draft
yaananth wants to merge 2 commits intoactions:mainfrom
Draft
fix: expand commit hash regex to support SHA-256 (64-char) hashes#4347yaananth wants to merge 2 commits intoactions:mainfrom
yaananth wants to merge 2 commits intoactions:mainfrom
Conversation
- update WellKnownRegularExpressions to match both 40-char (SHA-1) and 64-char (SHA-256) hex strings - add CommitHash constant as canonical name while keeping SHA1 for backward compatibility - remove dead _validSha1 field in RepositoryPlugin v1.0 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
salmanmkc
reviewed
Apr 15, 2026
| private static readonly Lazy<Regex> s_validSha1 = new Lazy<Regex>(() => new Regex( | ||
| @"\b[0-9a-f]{40}\b", | ||
| // 40 or 64 hex characters (SHA-1 or SHA-256 commit hash) | ||
| private static readonly Lazy<Regex> s_validCommitHash = new Lazy<Regex>(() => new Regex( |
Contributor
There was a problem hiding this comment.
The regex change looks correct, but WellKnownRegularExpressions currently has no dedicated unit tests.
Would be good if we could add a test class (e.g. src/Test/L0/Sdk/WellKnownRegularExpressionsL0.cs alongside the existing ExpressionParserL0.cs) with these minimum:
- 40-char hex → matches (regression guard)
- 64-char hex → matches (the new case this PR adds)
- 63-char and 65-char hex → do NOT match (boundary)
- Mixed-case 64-char → matches (
IgnoreCasestill works)
Would be good to avoid a regression in the future, in-case a future change breaks 64-char support to avoid it going undetected since nothing in CI directly tests it.
| @@ -24,7 +25,8 @@ public static Lazy<Regex> GetRegex(String regexType) | |||
| case IPv4Address: | |||
| return s_validIPv4Address; | |||
| case SHA1: | |||
Member
There was a problem hiding this comment.
do we need to remove the SHA1 and update all the caller to use the CommitHash?
Add dedicated test class covering: - 40-char SHA-1 match (regression guard) - 64-char SHA-256 match (new behavior) - 63/65-char boundary rejection - Mixed-case matching (IgnoreCase) - SHA1 and CommitHash keys return same regex instance - Unknown key returns null Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Summary
Expand the core commit-hash regex in
WellKnownRegularExpressionsto support both SHA-1 (40-char) and SHA-256 (64-char) commit hashes, preparing the runner for Git's SHA-256 transition.Changes
WellKnownRegularExpressions.cs: Update regex from\b[0-9a-f]{40}\bto\b(?:[0-9a-f]{40}|[0-9a-f]{64})\b; addCommitHashconstant as canonical name while keepingSHA1for backward compatibility; rename internal field froms_validSha1tos_validCommitHashRepositoryPlugin.cs(v1.0): Remove dead_validSha1field that was declared but never usedValidation
dev.sh build Debug)dev.sh test Debug)SHA1constant and all callsites unchangedContext
Automated by
project-board-agents-pluginvia/project-board-agents:leadBoard: https://github.com/orgs/github/projects/24272/views/1
Item: [P0] Fix core SHA-1 regex in actions/runner WellKnownRegularExpressions.cs
Run: sha256-p0-runner-00050