mirror of
https://github.com/discourse/discourse-table-builder.git
synced 2026-09-16 23:02:13 -04:00
FIX: do not edit wrong table when post has uploads (#37)
Previously, the regex was catching uploads as well as tables. This change ensures only strict tables are matched by requiring that matches start with the pipe character. Also adds a unit test for `findTableRegex` to describe the expected behaviour of the helper.
This commit is contained in:
@@ -46,10 +46,10 @@ export function arrayToTable(array, columns) {
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns a regular experssion finding all markdown tables
|
||||
* @returns a regular expression finding all markdown tables
|
||||
*/
|
||||
export function findTableRegex() {
|
||||
return /((\r?){2}|^)([^\r\n]*\|[^\r\n]*(\r?\n)?)+(?=(\r?\n){2}|$)/gm;
|
||||
return /((\r?){2}|^)(^\|[^\r\n]*(\r?\n)?)+(?=(\r?\n){2}|$)/gm;
|
||||
}
|
||||
|
||||
export function tokenRange(tokens, start, end) {
|
||||
|
||||
@@ -197,10 +197,10 @@ export default class SpreadsheetEditor extends Component {
|
||||
const tableToEdit = raw.match(findTableRegex());
|
||||
let editedTable;
|
||||
|
||||
if (tableToEdit.length > 1) {
|
||||
if (tableToEdit.length) {
|
||||
editedTable = raw.replace(tableToEdit[tableId], newRaw);
|
||||
} else {
|
||||
editedTable = raw.replace(tableToEdit[0], newRaw);
|
||||
return raw;
|
||||
}
|
||||
|
||||
// replace null characters
|
||||
|
||||
Reference in New Issue
Block a user