Merge "Fix linking pattern to allow trailing tilde and dash chars"
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 c6bfb74..e810637 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
@@ -126,7 +126,7 @@
this.repoCommentLinks = repoCommentLinks;
// Always linkify URLs starting with https?://
this.repoCommentLinks['ALWAYS_LINK_HTTP'] = {
- match: '(https?://\\S+[\\w/])',
+ match: '(https?://\\S+[\\w/~-])',
link: '$1',
enabled: true,
};
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 7bc0b11..becfbc2 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
@@ -210,35 +210,19 @@
});
test('does default linking', async () => {
- element.content = 'http://www.google.com';
- await element.updateComplete;
- assert.shadowDom.equal(
- element,
- /* HTML*/ `
- <pre class="plaintext">
- <a
- href="http://www.google.com"
- rel="noopener noreferrer"
- target="_blank"
- >http://www.google.com</a>
- </pre>
- `
- );
+ const checkLinking = async (url: string) => {
+ element.content = url;
+ await element.updateComplete;
+ const a = queryAndAssert<HTMLElement>(element, 'a');
+ assert.equal(a.getAttribute('href'), url);
+ assert.equal(a.innerText, url);
+ };
- element.content = 'https://www.google.com';
- await element.updateComplete;
- assert.shadowDom.equal(
- element,
- /* HTML*/ `
- <pre class="plaintext">
- <a
- href="https://www.google.com"
- rel="noopener noreferrer"
- target="_blank"
- >https://www.google.com</a>
- </pre>
- `
- );
+ await checkLinking('http://www.google.com');
+ await checkLinking('https://www.google.com');
+ await checkLinking('https://www.google.com/');
+ await checkLinking('https://www.google.com/asdf~');
+ await checkLinking('https://www.google.com/asdf-');
});
});
@@ -678,43 +662,18 @@
});
test('does default linking', async () => {
- element.content = 'http://www.google.com';
- await element.updateComplete;
- assert.shadowDom.equal(
- element,
- /* HTML*/ `
- <marked-element>
- <div slot="markdown-html" class="markdown-html">
- <p>
- <a
- href="http://www.google.com"
- rel="noopener noreferrer"
- target="_blank"
- >http://www.google.com</a>
- </p>
- </div>
- </marked-element>
- `
- );
+ const checkLinking = async (url: string) => {
+ element.content = url;
+ await element.updateComplete;
+ const a = queryAndAssert<HTMLElement>(element, 'a');
+ const p = queryAndAssert<HTMLElement>(element, 'p');
+ assert.equal(a.getAttribute('href'), url);
+ assert.equal(p.innerText, url);
+ };
- element.content = 'https://www.google.com';
- await element.updateComplete;
- assert.shadowDom.equal(
- element,
- /* HTML*/ `
- <marked-element>
- <div slot="markdown-html" class="markdown-html">
- <p>
- <a
- href="https://www.google.com"
- rel="noopener noreferrer"
- target="_blank"
- >https://www.google.com</a>
- </p>
- </div>
- </marked-element>
- `
- );
+ await checkLinking('http://www.google.com');
+ await checkLinking('https://www.google.com');
+ await checkLinking('https://www.google.com/');
});
suite('user suggest fix', () => {