From 0ad66571bf1f9b7bc4550862dd7a9a5f39684ddc Mon Sep 17 00:00:00 2001 From: Bob Du Date: Tue, 11 Jun 2024 09:02:09 +0800 Subject: [PATCH] [JENKINS-73246] Fix text shown in unexpected locale (#9370) Signed-off-by: Bob Du --- .../main/java/hudson/model/Descriptor.java | 4 ++++ .../hudson/GetLocaleStaticHelpUrlTest.java | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/core/src/main/java/hudson/model/Descriptor.java b/core/src/main/java/hudson/model/Descriptor.java index 817115c3ad17..32b9f1dd0cf0 100644 --- a/core/src/main/java/hudson/model/Descriptor.java +++ b/core/src/main/java/hudson/model/Descriptor.java @@ -1007,6 +1007,10 @@ public static URL getStaticHelpUrl(StaplerRequest req, Klass c, String suffix if (url != null) return url; url = c.getResource(base + '_' + locale.getLanguage() + ".html"); if (url != null) return url; + if (locale.getLanguage().equals("en")) { + url = c.getResource(base + ".html"); + if (url != null) return url; + } } // default diff --git a/core/src/test/java/hudson/GetLocaleStaticHelpUrlTest.java b/core/src/test/java/hudson/GetLocaleStaticHelpUrlTest.java index 5fd822bc1c55..a61fc0d54656 100644 --- a/core/src/test/java/hudson/GetLocaleStaticHelpUrlTest.java +++ b/core/src/test/java/hudson/GetLocaleStaticHelpUrlTest.java @@ -36,6 +36,7 @@ import java.util.Enumeration; import java.util.Locale; import org.junit.jupiter.api.Test; +import org.jvnet.hudson.test.Issue; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.lang.Klass; @@ -191,6 +192,24 @@ public void getStaticHelpUrlAcceptZhResMore() { assertThatLocaleResourceIs(id, "help-id_zh_CN.html"); } + @Issue("JENKINS-73246") + @Test + public void getStaticHelpUrlAcceptEnFirst() { + // Accept-Language: en-US,en;q=0.9,de;q=0.8 + StaplerRequest req = mockStaplerRequest( + Locale.US, + Locale.ENGLISH, + Locale.GERMAN + ); + + Klass klass = mockKlass( + "help-id.html", + "help-id_de.html" + ); + URL id = Descriptor.getStaticHelpUrl(req, klass, "-id"); + assertThatLocaleResourceIs(id, "help-id.html"); + } + private StaplerRequest mockStaplerRequest(Locale... localeArr) { StaplerRequest req = mock(StaplerRequest.class); Enumeration locales = Collections.enumeration(Arrays.asList(localeArr));