Skip to content

Commit 9226667

Browse files
authored
Fix regex used to match docker SHA256 (#37045)
#### Description Fix the regex used to match docker SHA256. #### Link to tracking issue Fix #36239 #### Testing Local run of `make` at `internal/docker` - caveat: if some other test code depending on this may fail if it is not using a SHA256 with exactly 64 chars it will be broken by this change. I will add any test fix for any such case detected via CI. #### Documentation N/A
1 parent 5641945 commit 9226667

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: 'bug_fix'
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: 'internal/docker'
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Fix image matching regular expression to properly match SHA256 strings.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [36239]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: This affects the `docker_observer` extension.
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

internal/common/docker/images.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"go.uber.org/zap"
1111
)
1212

13-
var extractImageRegexp = regexp.MustCompile(`^(?P<repository>([^/\s]+/)?([^:\s]+))(:(?P<tag>[^@\s]+))?(@sha256:(?P<sha256>\d+))?$`)
13+
var extractImageRegexp = regexp.MustCompile(`^(?P<repository>([^/\s]+/)?([^:\s]+))(:(?P<tag>[^@\s]+))?(@sha256:(?P<sha256>[A-Fa-f0-9]{64}))?$`)
1414

1515
type ImageRef struct {
1616
Repository string

internal/common/docker/images_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ func TestDockerImageToElements(t *testing.T) {
4545
{
4646
name: "image with sha256 hash",
4747
args: args{
48-
image: "alpine:test@sha256:00000000000000",
48+
image: "alpine:test@sha256:dbc66f8c46d4cf4793527ca0737d73527a2bb830019953c2371b5f45f515f1a8",
4949
},
5050
wantRepository: "alpine",
5151
wantTag: "test",
52-
wantSHA256: "00000000000000",
52+
wantSHA256: "dbc66f8c46d4cf4793527ca0737d73527a2bb830019953c2371b5f45f515f1a8",
5353
wantErr: false,
5454
},
5555
{

0 commit comments

Comments
 (0)