Change Summary

  • Simplify regular expression checking for validity of Image Reference to fix Catastrophic Backtracking for long custom images with illegal characters in tag

Issue

  • https://github.com/spring-projects/spring-boot/issues/39246

Comment From: scottfrederick

Thanks @wanger26. This change looked good to me, but a test somewhere else in the project failed. A test added to ImageReferenceTests like this passes without the change in this PR (as it should) but fails after the change:

    @Test
    void ofSimpleNameWithSingleCharacterSuffix() {
        ImageReference reference = ImageReference.of("ubuntu-a");
        assertThat(reference.getDomain()).isEqualTo("docker.io");
        assertThat(reference.getName()).isEqualTo("library/ubuntu-a");
        assertThat(reference.getTag()).isNull();
        assertThat(reference.getDigest()).isNull();
        assertThat(reference).hasToString("docker.io/library/ubuntu-a");
    }

A single character (lower-case alpha or numeric) after a - separator does not parse correctly.

Note that the RegEx, ImageReference and ImageReferenceTests are all (nearly) duplicated in the project. The RegEx and ImageReferenceTests classes will need the same change in both places.

Do you want to try to address this issue?

Comment From: wanger26

@scottfrederick I can address the build issue as well as make the recommended adjustments. I am going to steal that test case too if you don't mind to make sure we get it right :100:

Comment From: scottfrederick

Thanks very much @wanger26. The change has been merged along with a small polishing commit in c93acdafbd6de650f5afc7e2d33ff4689f7907c4.