Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Searching on a REGEX character will break die highlighting filter #857

Closed
kees-hoogerheide-teampeak opened this issue Oct 28, 2024 · 1 comment

Comments

@kees-hoogerheide-teampeak

Describe the bug

When you only enter a + sign in the searchbar, the regex which is used to highlight the search result will error, breaking the javascript on the page.

To Reproduce

Steps to reproduce the behavior:

  1. Go to any of the index pages of easy admin
  2. Enter a + in the search bar and press on search
  3. In the console you will see a error `
  4. See error [Uncaught SyntaxError: nothing to repeat](app.18be9a54.js:2 Uncaught SyntaxError: Invalid regular expression: /+/i: Nothing to repeat (at app.18be9a54.js:2:154890))

Expected behavior

What should happen is, the page should reload and highlight all + characters in the found results.

Screenshots/Logs

app.18be9a54.js:2 Uncaught SyntaxError: Invalid regular expression: /+/i: Nothing to repeat (at app.18be9a54.js:2:154890)
    at new RegExp (<anonymous>)
    at t.rt (app.18be9a54.js:2:154890)
    at new t (app.18be9a54.js:2:152255)
    at HTMLDocument.<anonymous> (app.18be9a54.js:2:151550)
rt @ app.18be9a54.js:2
t @ app.18be9a54.js:2
(anonymous) @ app.18be9a54.js:2

Server Infos (please complete the following information):

  • OS: Windows 11, Chrome (Version 130.0.6723.70 (Official Build) (64-bit))
  • EasyAdmin Version: v4.13.5

Additional context

The error comes from "easycorp\easyadmin-bundle\assets\js\autocomplete.js" line 184.
Inside the method #createSearchHighlight() where the characters aren't being escaped and directly taken from the input field:

#createSearchHighlight() {
    ...
    const searchQueryTerms = tokenizeString(searchElement.value);
    const searchQueryTermsHighlightRegexp = new RegExp(searchQueryTerms.join('|'), 'i');
    ...
}
@Blumlaut
Copy link
Owner

Your EasyAdmin is in another castle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants