Commit f796f1cf authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'sh-fix-paste-markdown-from-diff' into 'master'

Avoid copying diffs as Markdown tables

Closes #213033

See merge request gitlab-org/gitlab!30572
parents 7c61599f a5a3ed15
...@@ -47,7 +47,8 @@ export default class PasteMarkdownTable { ...@@ -47,7 +47,8 @@ export default class PasteMarkdownTable {
const htmlData = this.data.getData('text/html'); const htmlData = this.data.getData('text/html');
this.doc = new DOMParser().parseFromString(htmlData, 'text/html'); this.doc = new DOMParser().parseFromString(htmlData, 'text/html');
const tables = this.doc.querySelectorAll('table'); // Avoid formatting lines that were copied from a diff
const tables = this.doc.querySelectorAll('table:not(.diff-wrap-lines)');
// We're only looking for exactly one table. If there happens to be // We're only looking for exactly one table. If there happens to be
// multiple tables, it's possible an application copied data into // multiple tables, it's possible an application copied data into
......
---
title: Avoid copying diffs as Markdown tables
merge_request: 30572
author:
type: fixed
...@@ -57,6 +57,18 @@ describe('PasteMarkdownTable', () => { ...@@ -57,6 +57,18 @@ describe('PasteMarkdownTable', () => {
expect(new PasteMarkdownTable(data).isTable()).toBe(false); expect(new PasteMarkdownTable(data).isTable()).toBe(false);
}); });
it('returns false when the table copy comes from a diff', () => {
data.types = ['text/html', 'text/plain'];
data.getData = jest.fn().mockImplementation(mimeType => {
if (mimeType === 'text/html') {
return '<table class="diff-wrap-lines"><tr><td>First</td><td>Second</td></tr></table>';
}
return 'First\tSecond';
});
expect(new PasteMarkdownTable(data).isTable()).toBe(false);
});
}); });
describe('convertToTableMarkdown', () => { describe('convertToTableMarkdown', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment