Skip to content

Commit 54beb6a

Browse files
committed
Escape parenthesis for links in Markdown format
1 parent 0f854a9 commit 54beb6a

File tree

2 files changed

+29
-1
lines changed
  • headless-services/commons/commons-util/src

2 files changed

+29
-1
lines changed

headless-services/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/Renderables.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ public void renderAsMarkdown(StringBuilder buffer) {
210210
buffer.append(']');
211211
if (url != null) {
212212
buffer.append('(');
213-
buffer.append(url);
213+
// Escape parenthesis for the MD format
214+
buffer.append(url.replace("(", "%28").replace(")", "%29"));
214215
buffer.append(')');
215216
}
216217
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Broadcom, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Broadcom, Inc. - initial API and implementation
10+
*******************************************************************************/
11+
package org.springframework.ide.vscode.commons.util;
12+
13+
import static org.assertj.core.api.Assertions.assertThat;
14+
15+
import org.junit.jupiter.api.Test;
16+
17+
public class RenderablesTest {
18+
19+
@Test
20+
void escapeParenthesisForMardownLink() {
21+
Renderable r = Renderables.link("my-link-with-parenthesis", "https://foo.com/index(1).html");
22+
StringBuilder sb = new StringBuilder();
23+
r.renderAsMarkdown(sb);
24+
assertThat(sb.toString()).isEqualTo("[my-link-with-parenthesis](https://foo.com/index%281%29.html)");
25+
}
26+
27+
}

0 commit comments

Comments
 (0)