Skip to content

A platform for community discussion. Free, open, simple.

FIX: Catch fast edit selections that are too massive to edit. (#33777)

Gary Pendergast4245311cad48
diff --git a/app/assets/javascripts/discourse/app/components/post-text-selection.gjs b/app/assets/javascripts/discourse/app/components/post-text-selection.gjs
index a8f9749d489..c4cd2603805 100644
--- a/app/assets/javascripts/discourse/app/components/post-text-selection.gjs
+++ b/app/assets/javascripts/discourse/app/components/post-text-selection.gjs
@@ -315,15 +315,21 @@ export default class PostTextSelection extends Component {
if (supportsFastEdit) {
const regexp = new RegExp(escapeRegExp(quoteState.buffer), "gi");
- const matches = cooked.innerHTML.match(regexp);
-
- if (
- quoteState.buffer.length === 0 ||
- quoteState.buffer.includes("|") || // tables are too complex
- quoteState.buffer.match(/\n/g) || // linebreaks are too complex
- quoteState.buffer.match(/[‚‘’„“”«»‹›™±…→←↔¶]/g) || // typopgraphic characters are too complex
- matches?.length !== 1 // duplicates are too complex
- ) {
+ try {
+ const matches = cooked.innerHTML.match(regexp);
+
+ if (
+ quoteState.buffer.length === 0 ||
+ quoteState.buffer.includes("|") || // tables are too complex
+ quoteState.buffer.match(/\n/g) || // linebreaks are too complex
+ quoteState.buffer.match(/[‚‘’„“”«»‹›™±…→←↔¶]/g) || // typopgraphic characters are too complex
+ matches?.length !== 1 // duplicates are too complex
+ ) {
+ supportsFastEdit = false;
+ }
+ } catch {
+ // If the regex is too large, it will throw an error.
+ // In this case, we just disable fast edit.
supportsFastEdit = false;
}
}