Skip to content

fix: markdown editor crashes on older iOS/Safari due to unsupported regex#4349

Merged
cemreinanc merged 2 commits intomainfrom
fix/4238-markdown-editor-regex
Feb 16, 2026
Merged

fix: markdown editor crashes on older iOS/Safari due to unsupported regex#4349
cemreinanc merged 2 commits intomainfrom
fix/4238-markdown-editor-regex

Conversation

@cemreinanc
Copy link
Copy Markdown
Contributor

@cemreinanc cemreinanc commented Feb 13, 2026

Fixes #4238

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved dollar sign escaping in the markdown editor to prevent double-escaping and better preserve escaped mathematical expressions.
  • Tests

    • Added test coverage for edge cases in dollar sign and escaped delimiter handling.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 13, 2026

Cleanup: Preview Environment Removed

The preview environment for this PR has been destroyed.

Resource Status
🌐 Preview App Deleted
🗄️ PostgreSQL Branch Deleted
⚡ Redis Database Deleted
🔧 GitHub Deployments Removed
📦 Docker Image Retained (auto-cleanup via GHCR policies)

Cleanup triggered by PR close at 2026-02-16T11:45:27Z

@cemreinanc cemreinanc requested a review from ncarazon February 13, 2026 15:31
Copy link
Copy Markdown
Contributor

@ncarazon ncarazon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 16, 2026

📝 Walkthrough

Walkthrough

This pull request fixes a critical compatibility issue affecting older iOS/Safari versions by removing unsupported negative lookbehind regex patterns from the markdown editor. The math expression preprocessing logic is restructured to use position-aware escaping detection instead of lookaround assertions, with corresponding updates to dollar sign escaping and new test coverage for edge cases.

Changes

Cohort / File(s) Summary
Math Expression Preprocessing
front_end/src/components/markdown_editor/helpers.ts
Replaced negative lookbehind regex patterns with simplified regexes and introduced isEscapedAt() helper for context-aware escaping detection. Restructured math placeholder management to directly inspect character positions instead of lookaround assertions, maintaining equivalent escaping behavior across browser versions.
Dollar Sign Escaping
front_end/src/components/markdown_editor/plugins/equation/components/equation_editor.tsx
Replaced regex-based dollar sign escaping with callback-based iteration that checks for preceding backslashes, avoiding negative lookbehind syntax while preserving escaping logic.
Test Coverage
front_end/src/components/markdown_editor/__tests__/helpers.test.ts
Added test cases validating double-escaping prevention and escaped block delimiter preservation in the dollar sign escaping suite.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 Farewell, lookbehinds! A hop and a skip,
We've caught those pesky dollars mid-trip,
With escaping checks in every position,
Safari now dances with our ambition! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary change: removing unsupported regex features (negative lookbehind) that cause crashes on older iOS/Safari versions.
Linked Issues check ✅ Passed The PR successfully removes negative lookbehind syntax from BLOCK_MATH_REGEX and INLINE_MATH_REGEX, implementing alternative escaping logic with isEscapedAt helper to prevent crashes on Safari < 16.4 [#4238].
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the regex compatibility issue: regex simplification, escaping helper implementation, and corresponding test coverage for edge cases.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/4238-markdown-editor-regex

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
front_end/src/components/markdown_editor/plugins/equation/components/equation_editor.tsx (1)

19-24: Good: removes negative lookbehind for Safari compatibility.

One minor note: this only checks a single preceding \, whereas helpers.ts uses isEscapedAt which correctly handles consecutive backslashes (e.g., \\$ where the backslash itself is escaped). In the equation editor context this is unlikely to matter, but importing and reusing isEscapedAt would improve consistency.

♻️ Optional: use isEscapedAt for consistency
+import { isEscapedAt } from "../../helpers"; // would need to export it
+
 value = value.replace(/\$/g, (match, offset, input) => {
-  if (offset > 0 && input[offset - 1] === "\\") {
+  if (isEscapedAt(input, offset)) {
     return match;
   }
   return "\\$";
 });

@cemreinanc cemreinanc merged commit 1f8cbce into main Feb 16, 2026
15 checks passed
@cemreinanc cemreinanc deleted the fix/4238-markdown-editor-regex branch February 16, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown editor crashes on older iOS/Safari due to unsupported regex

2 participants