Skip to content

Commit

Permalink
Merge pull request #9415 from krisstern/chore/stable-2.452/backportin…
Browse files Browse the repository at this point in the history
…g-2.452.3-1

Backporting for LTS 2.452.3
  • Loading branch information
krisstern authored Jun 26, 2024
2 parents 3633ce3 + 1eea5c5 commit 71824f0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/hudson/model/Descriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/org/jenkins/ui/symbol/Symbol.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import jenkins.model.Jenkins;
import org.apache.commons.io.IOUtils;

Expand Down Expand Up @@ -55,13 +56,13 @@ public static String get(@NonNull SymbolRequest request) {
.computeIfAbsent(identifier, key -> new ConcurrentHashMap<>())
.computeIfAbsent(name, key -> loadSymbol(identifier, key));
if ((tooltip != null && !tooltip.isBlank()) && (htmlTooltip == null || htmlTooltip.isBlank())) {
symbol = symbol.replaceAll("<svg", "<svg tooltip=\"" + Functions.htmlAttributeEscape(tooltip) + "\"");
symbol = symbol.replaceAll("<svg", Matcher.quoteReplacement("<svg tooltip=\"" + Functions.htmlAttributeEscape(tooltip) + "\""));
}
if (htmlTooltip != null && !htmlTooltip.isBlank()) {
symbol = symbol.replaceAll("<svg", "<svg data-html-tooltip=\"" + Functions.htmlAttributeEscape(htmlTooltip) + "\"");
symbol = symbol.replaceAll("<svg", Matcher.quoteReplacement("<svg data-html-tooltip=\"" + Functions.htmlAttributeEscape(htmlTooltip) + "\""));
}
if (id != null && !id.isBlank()) {
symbol = symbol.replaceAll("<svg", "<svg id=\"" + Functions.htmlAttributeEscape(id) + "\"");
symbol = symbol.replaceAll("<svg", Matcher.quoteReplacement("<svg id=\"" + Functions.htmlAttributeEscape(id) + "\""));
}
if (classes != null && !classes.isBlank()) {
symbol = symbol.replaceAll("<svg", "<svg class=\"" + Functions.htmlAttributeEscape(classes) + "\"");
Expand Down
19 changes: 19 additions & 0 deletions core/src/test/java/hudson/GetLocaleStaticHelpUrlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<Locale> locales = Collections.enumeration(Arrays.asList(localeArr));
Expand Down
17 changes: 17 additions & 0 deletions test/src/test/java/org/jenkins/ui/symbol/SymbolJenkinsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.DisplayName;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.RealJenkinsRule;

Expand All @@ -15,6 +16,22 @@ public class SymbolJenkinsTest {
public RealJenkinsRule rjr = new RealJenkinsRule()
.addPlugins("plugins/design-library.jpi", "plugins/prism-api.jpi", "plugins/bootstrap5-api.jpi");

@Test
@Issue("JENKINS-73243")
@DisplayName("When resolving a symbol where the tooltip contains '$' no error is thrown")
public void dollarInToolTipSucceeds() throws Throwable {
rjr.then(SymbolJenkinsTest::_dollarInTooltipSucceeds);
}

private static void _dollarInTooltipSucceeds(JenkinsRule j) {
String symbol = Symbol.get(new SymbolRequest.Builder()
.withName("add")
.withTooltip("$test")
.build()
);
assertThat(symbol, containsString("tooltip=\"$test\""));
}

@Test
@DisplayName("When resolving a symbol from a missing plugin, the placeholder is generated instead")
public void missingSymbolFromPluginDefaultsToPlaceholder() throws Throwable {
Expand Down

0 comments on commit 71824f0

Please sign in to comment.