Repository navigation
Conversation
|
Someone is attempting to deploy a commit to the Consensys Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: crash in Tutorials search highlighting
Problem
highlightSearchText()insrc/components/TutorialsPage/TutorialCard.tsxbuilt aRegExpstraight from the user's search input, without escaping regex metacharacters:
Ordinary search text therefore produced invalid patterns —
c++→(c++)(SyntaxError: Nothing to repeat),(→((|)(unterminated group),[→([|)(unterminated character class).Because
new RegExp()is called during render, the throw is unhandled: the/tutorialspage crashes. The offending text stays in the search box, so the user cannot recover
without a full page reload.
The same input also highlighted matches incorrectly:
.matched any character and|acted as alternation instead of a literal.Fix
Escape every search term before joining it into the pattern:
Search terms are now always matched literally, and the page no longer throws.
Scope
src/components/TutorialsPage/TutorialCard.tsx(the component actuallyrendered by
TutorialsPage/index.tsx).index.tsxalready uses
String.includes()and was untouched.GuideCard.tsxis not imported anywhere, andindex.tsxkeeps anunused copy of the old
highlightSearchText. Both should be removed separately to keep thediff here minimal.
Note
Low Risk
Single-function UI change with no auth, data, or API impact; reduces render-time crash risk on the tutorials page.
Overview
Fixes /tutorials page crashes when the search box contains regex special characters (e.g.
c++,(,[).highlightSearchTextinTutorialCard.tsxnow escapes each search term before building the highlightRegExp, so terms are matched literally andnew RegExp()no longer throws during render. Normal alphanumeric searches behave the same; only previously broken or incorrectly interpreted patterns are fixed.Reviewed by Cursor Bugbot for commit 1c5e2fc. Bugbot is set up for automated code reviews on this repo. Configure here.