Merge "Fallback to markdown-less rendering for content that is too long"
diff --git a/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text.ts b/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text.ts
index d765eeb..c8663e6 100644
--- a/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text.ts
+++ b/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text.ts
@@ -119,7 +119,7 @@
}
override render() {
- if (this.markdown) {
+ if (this.markdown && this.content.length < this.MARKDOWN_LIMIT) {
return this.renderAsMarkdown();
} else {
return this.renderAsPlaintext();
@@ -181,9 +181,7 @@
// rewrites have been abused to attempt an XSS attack.
return html`
<marked-element
- .markdown=${this.escapeAllButBlockQuotes(
- this.limitLength(this.content)
- )}
+ .markdown=${this.escapeAllButBlockQuotes(this.content)}
.breaks=${true}
.renderer=${customRenderer}
.callback=${(_error: string | null, contents: string) =>
@@ -194,11 +192,6 @@
`;
}
- private limitLength(text: string) {
- if (text.length < this.MARKDOWN_LIMIT) return text;
- return text.slice(0, this.MARKDOWN_LIMIT).concat('...');
- }
-
private escapeAllButBlockQuotes(text: string) {
// Escaping the message should be done first to make sure user's literal
// input does not get rendered without affecting html added in later steps.
diff --git a/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text_test.ts b/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text_test.ts
index 3e6a266..9acca0f 100644
--- a/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text_test.ts
+++ b/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text_test.ts
@@ -264,21 +264,38 @@
test('does not render if too long', async () => {
element.content = `text
- \ntext with plain link: google.com
- \ntext with config link: LinkRewriteMe
- \ntext without a link: NotA Link 15 cats
- \ntext with complex link: A Link 12`;
+ text with plain link: google.com
+ text with config link: LinkRewriteMe
+ text without a link: NotA Link 15 cats
+ text with complex link: A Link 12`;
element.MARKDOWN_LIMIT = 10;
await element.updateComplete;
assert.shadowDom.equal(
element,
/* HTML */ `
- <marked-element>
- <div class="markdown-html" slot="markdown-html">
- <p>text<br />...</p>
- </div>
- </marked-element>
+ <pre class="plaintext">
+ text
+ text with plain link:
+ <a href="http://google.com" rel="noopener" target="_blank">google.com</a>
+ text with config link:
+ <a
+ href="http://google.com/LinkRewriteMe"
+ rel="noopener"
+ target="_blank"
+ >
+ LinkRewriteMe
+ </a>
+ text without a link: NotA Link 15 cats
+ text with complex link: A
+ <a
+ href="http://localhost/page?id=12"
+ rel="noopener"
+ target="_blank"
+ >
+ Link 12
+ </a>
+ </pre>
`
);
});