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-70730 Don't remove id inside symbol #7689

Merged
merged 1 commit into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion core/src/main/java/org/jenkins/ui/symbol/Symbol.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ private static String loadSymbol(String namespace, String name) {
.replaceAll("(class=\").*?(\")", "")
.replaceAll("(tooltip=\").*?(\")", "")
.replaceAll("(data-html-tooltip=\").*?(\")", "")
.replaceAll("(id=\").*?(\")", "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that can lead to a duplicated id for the svg itself.
Assume the svg has an id at the root <svg id="symbolid" .../>
Now I want to use that svg with
<l:icon sec="mysymbol" id="myid"/>
The result will be 2 id attributes I think.

Copy link
Member Author

@timja timja Mar 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could but why would the svg have an id at the root baked into it?

Otherwise to fix it this string replace hack needs replacing with a dom library that only operates on the svg tag and not children.

.replace("stroke:#000", "stroke:currentColor");
}

Expand Down
12 changes: 12 additions & 0 deletions core/src/test/java/org/jenkins/ui/symbol/SymbolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.Issue;

public class SymbolTest {
public static final String SCIENCE_PATH;
Expand Down Expand Up @@ -190,4 +191,15 @@ void getSymbol_notSettingTooltipDoesntAddTooltipAttribute_evenWithAmpersand() {
assertThat(symbol, containsString(SCIENCE_PATH));
assertThat(symbol, not(containsString("tooltip")));
}

@Test
@DisplayName("IDs in symbol should not be removed")
@Issue("JENKINS-70730")
void getSymbol_idInSymbolIsPresent() {
String symbol = Symbol.get(new SymbolRequest.Builder()
.withId("some-random-id")
.withName("with-id").build());

assertThat(symbol, containsString("id=\"a\""));
}
}
14 changes: 14 additions & 0 deletions core/src/test/resources/images/symbols/with-id.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.