Skip to content

Commit d251afd

Browse files
Merge 25.11 to 26.2
2 parents cda27b2 + 2ad5817 commit d251afd

4 files changed

Lines changed: 84 additions & 9 deletions

File tree

api/src/org/labkey/api/data/dialect/PkMetaDataReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ public int getKeySeq() throws SQLException
4444

4545
public String getKeyName() throws SQLException
4646
{
47-
return _rsCols.getString("pk_name");
47+
return _rsCols.getString("PK_NAME");
4848
}
4949
}

core/src/org/labkey/core/wiki/MarkdownServiceImpl.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@
2323
import org.commonmark.ext.image.attributes.ImageAttributesExtension;
2424
import org.commonmark.node.Node;
2525
import org.commonmark.parser.Parser;
26+
import org.commonmark.renderer.html.HtmlNodeRendererContext;
2627
import org.commonmark.renderer.html.HtmlRenderer;
28+
import org.commonmark.renderer.html.CoreHtmlNodeRenderer;
29+
import org.commonmark.node.HtmlInline;
30+
import org.commonmark.node.HtmlBlock;
2731
import org.labkey.api.markdown.MarkdownService;
2832

2933
import java.util.List;
34+
import java.util.Set;
3035

3136
public class MarkdownServiceImpl implements MarkdownService
3237
{
@@ -55,10 +60,65 @@ public MarkdownServiceImpl()
5560
.softbreak("<br>\n") // See Issue #34169
5661
.sanitizeUrls(true)
5762
.escapeHtml(true)
63+
.nodeRendererFactory(CommentNodeRenderer::new)
5864
.extensions(extensions)
5965
.build();
6066
}
6167

68+
private static class CommentNodeRenderer extends CoreHtmlNodeRenderer
69+
{
70+
private final HtmlNodeRendererContext _context;
71+
72+
public CommentNodeRenderer(HtmlNodeRendererContext context)
73+
{
74+
super(context);
75+
_context = context;
76+
}
77+
78+
@Override
79+
public Set<Class<? extends Node>> getNodeTypes()
80+
{
81+
return Set.of(HtmlInline.class, HtmlBlock.class);
82+
}
83+
84+
@Override
85+
public void render(Node node)
86+
{
87+
if (node instanceof HtmlInline inline)
88+
{
89+
String literal = inline.getLiteral();
90+
if (isComment(literal))
91+
{
92+
_context.getWriter().raw(literal);
93+
}
94+
else
95+
{
96+
_context.getWriter().text(literal);
97+
}
98+
}
99+
else if (node instanceof HtmlBlock block)
100+
{
101+
String literal = block.getLiteral();
102+
if (isComment(literal))
103+
{
104+
_context.getWriter().raw(literal);
105+
}
106+
else
107+
{
108+
_context.getWriter().tag("p");
109+
_context.getWriter().text(literal);
110+
_context.getWriter().tag("/p");
111+
_context.getWriter().line();
112+
}
113+
}
114+
}
115+
116+
private boolean isComment(String literal)
117+
{
118+
return literal != null && literal.trim().startsWith("<!--") && literal.trim().endsWith("-->");
119+
}
120+
}
121+
62122
@Override
63123
public String toHtml(String mdText)
64124
{

core/src/org/labkey/core/wiki/MarkdownTestCase.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class MarkdownTestCase extends Assert
1515
@Test
1616
public void testMdHeadingToHtml()
1717
{
18-
MarkdownService markdownService = MarkdownService.get();
18+
MarkdownService markdownService = new MarkdownServiceImpl();
1919
String testMdText = "# This is a H1 header";
2020
String expectedHtmlText = "<div class=\"lk-markdown-container\"><h1 id=\"this-is-a-h1-header\">This is a H1 header</h1>\n</div>";
2121
String htmlText = markdownService.toHtml(testMdText);
@@ -28,7 +28,7 @@ public void testMdHeadingToHtml()
2828
@Test
2929
public void testMdBoldToHtml()
3030
{
31-
MarkdownService markdownService = MarkdownService.get();
31+
MarkdownService markdownService = new MarkdownServiceImpl();
3232
String testMdText = "**This is bold text**";
3333
String expectedHtmlText = "<div class=\"lk-markdown-container\"><p><strong>This is bold text</strong></p>\n</div>";
3434
String htmlText = markdownService.toHtml(testMdText);
@@ -41,11 +41,10 @@ public void testMdBoldToHtml()
4141
@Test
4242
public void testMdHtmlTags()
4343
{
44-
MarkdownService markdownService = MarkdownService.get();
45-
44+
MarkdownService markdownService = new MarkdownServiceImpl();
4645
String testMdText = "<h2>header</h2>";
47-
String expectedHtmlText = "<div class=\"lk-markdown-container\"><p>&lt;h2&gt;header&lt;/h2&gt;</p>\n</div>";
4846
String htmlText = markdownService.toHtml(testMdText);
47+
String expectedHtmlText = "<div class=\"lk-markdown-container\"><p>&lt;h2&gt;header&lt;/h2&gt;</p>\n</div>";
4948
assertEquals("The MarkdownService failed to correctly escape html tags.", expectedHtmlText, htmlText);
5049

5150
testMdText = "<script>alert()</script>";
@@ -60,7 +59,7 @@ public void testMdHtmlTags()
6059
@Test
6160
public void testMdComplexToHtml()
6261
{
63-
MarkdownService markdownService = MarkdownService.get();
62+
MarkdownService markdownService = new MarkdownServiceImpl();
6463
// this sample of markdown and translation taken from part of: https://markdown-it.github.io/
6564
String testMdText = """
6665
---
@@ -341,4 +340,20 @@ public void testMdComplexToHtml()
341340
String htmlText = markdownService.toHtml(testMdText);
342341
assertEquals("The MarkdownService failed to correctly translate complex markdown text to html.", expectedHtmlText, htmlText);
343342
}
343+
@Test
344+
public void testHtmlComments()
345+
{
346+
MarkdownService markdownService = new MarkdownServiceImpl();
347+
348+
String testMdText = "Text before <!-- comment --> text after";
349+
String htmlText = markdownService.toHtml(testMdText);
350+
351+
assertTrue("Comment was encoded: " + htmlText, htmlText.contains("<!-- comment -->"));
352+
assertFalse("Comment should not be encoded: " + htmlText, htmlText.contains("&lt;!--"));
353+
354+
// Verification for <script> still being encoded
355+
String scriptMd = "<script>alert('hi')</script>";
356+
String scriptHtml = markdownService.toHtml(scriptMd);
357+
assertTrue("Script tags should still be encoded: " + scriptHtml, scriptHtml.contains("&lt;script&gt;"));
358+
}
344359
}

issues/src/org/labkey/issue/model/IssueManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ public HttpView getCustomSearchResult(User user, @NotNull String resourceIdentif
10241024
return null;
10251025
}
10261026

1027-
final IssueObject issue = getIssue(null, user, issueId);
1027+
final IssueObject issue = getIssue(null, user, issueId, false);
10281028
if (null == issue)
10291029
return null;
10301030
Container c = issue.lookupContainer();
@@ -1305,7 +1305,7 @@ public static WebdavResource resolve(String id)
13051305
return null;
13061306
}
13071307

1308-
final IssueObject issue = getIssue(null, User.getSearchUser(), issueId);
1308+
final IssueObject issue = getIssue(null, User.getSearchUser(), issueId, false);
13091309
if (null == issue)
13101310
return null;
13111311

0 commit comments

Comments
 (0)