Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-73243] quote replacement string in symbol tooltips #9347

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -14,6 +14,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand Down Expand Up @@ -72,13 +73,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
15 changes: 15 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 @@ -15,6 +15,21 @@ public class SymbolJenkinsTest {
public RealJenkinsRule rjr = new RealJenkinsRule()
.addPlugins("plugins/design-library.jpi", "plugins/prism-api.jpi", "plugins/bootstrap5-api.jpi");

@Test
mawinter69 marked this conversation as resolved.
Show resolved Hide resolved
@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
Loading