From 8da32c91674c014a494129dcec628f0902bc2473 Mon Sep 17 00:00:00 2001 From: Sagar Khushalani Date: Fri, 1 Oct 2021 15:54:30 -0500 Subject: [PATCH 1/2] Correct path to color-blind friendly GIFs This change corrects the path used when to return gifs when the color-blind option is turned on. --- .../java/hudson/plugins/greenballs/GreenBallFilter.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/hudson/plugins/greenballs/GreenBallFilter.java b/src/main/java/hudson/plugins/greenballs/GreenBallFilter.java index 36e1329..cb60800 100644 --- a/src/main/java/hudson/plugins/greenballs/GreenBallFilter.java +++ b/src/main/java/hudson/plugins/greenballs/GreenBallFilter.java @@ -80,11 +80,11 @@ private String mapImage(String uri) { ColorBlindProperty colorBlindProperty = user.getProperty(ColorBlindProperty.class); if (colorBlindProperty != null && colorBlindProperty.isEnabledColorBlindSupport()) { if ((m = patternBlue.matcher(uri)).find()) { - return basePath + "colorblind" + m.group(1) + "/green" + m.group(2) + ".gif"; + return basePath + "colorblind" + "/" + m.group(1) + "/green" + m.group(2) + ".gif"; } else if ((m = patternRed.matcher(uri)).find()) { - return basePath + "colorblind" + m.group(1) + "/red" + m.group(2) + ".gif"; + return basePath + "colorblind" + "/" + m.group(1) + "/red" + m.group(2) + ".gif"; } else if ((m = patternYellow.matcher(uri)).find()) { - return basePath + "colorblind" + m.group(1) + "/yellow" + m.group(2) + ".gif"; + return basePath + "colorblind" + "/" + m.group(1) + "/yellow" + m.group(2) + ".gif"; } return null; } From 8916ef692cdf418e9d5e9e05650f3253b52faaa6 Mon Sep 17 00:00:00 2001 From: Sagar Khushalani Date: Mon, 10 Jan 2022 09:13:12 -0600 Subject: [PATCH 2/2] Add test --- .../greenballs/GreenBallFilterTest.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/test/java/hudson/plugins/greenballs/GreenBallFilterTest.java b/src/test/java/hudson/plugins/greenballs/GreenBallFilterTest.java index 1c1d279..5bcc49c 100644 --- a/src/test/java/hudson/plugins/greenballs/GreenBallFilterTest.java +++ b/src/test/java/hudson/plugins/greenballs/GreenBallFilterTest.java @@ -30,6 +30,18 @@ static void patternMatchAnime(Matcher m) { assertThat(m.group(2), equalTo("_anime")); } + static void patternMatchColorblind(Matcher m) { + assertThat(m.find(), is(true)); + assertThat(m.group(1), equalTo("48x48")); + assertThat(m.group(2), equalTo("")); + } + + static void patternMatchColorblindAnime(Matcher m) { + assertThat(m.find(), is(true)); + assertThat(m.group(1), equalTo("48x48")); + assertThat(m.group(2), equalTo("_anime")); + } + @Test public void patternShouldMatch() { final Matcher m = GreenBallFilter.patternBlue.matcher("/nocacheImages/48x48/blue.gif"); @@ -69,4 +81,24 @@ public void patternShouldNotMatch() { final Matcher m3 = GreenBallFilter.patternRed.matcher("/nocacheImages/48x48/yello_anime.gif"); assertThat(m3.find(), is(false)); } -} \ No newline at end of file + + @Test + public void patternShouldMatchColorblind() { + final Matcher m = GreenBallFilter.patternBlue.matcher("/nocacheImages/colorblind/48x48/blue.gif"); + final Matcher m2 = GreenBallFilter.patternYellow.matcher("/nocacheImages/colorblind/48x48/yellow.gif"); + final Matcher m3 = GreenBallFilter.patternRed.matcher("/nocacheImages/colorblind/48x48/red.gif"); + patternMatchColorblind(m); + patternMatchColorblind(m2); + patternMatchColorblind(m3); + } + + @Test + public void patternShouldMatchColorblindAnime() { + final Matcher m = GreenBallFilter.patternBlue.matcher("/nocacheImages/colorblind/48x48/blue_anime.gif"); + final Matcher m2 = GreenBallFilter.patternYellow.matcher("/nocacheImages/colorblind/48x48/yellow_anime.gif"); + final Matcher m3 = GreenBallFilter.patternRed.matcher("/nocacheImages/colorblind/48x48/red_anime.gif"); + patternMatchColorblindAnime(m); + patternMatchColorblindAnime(m2); + patternMatchColorblindAnime(m3); + } +}