Skip to content

Commit

Permalink
Escape search string
Browse files Browse the repository at this point in the history
search function accept regex argument or converts it to regex if string is provider. If you tried search for \ it threw exception. This change fixes it.
  • Loading branch information
Joozty committed Nov 25, 2020
1 parent a42a576 commit ff43c26
Show file tree
Hide file tree
Showing 4 changed files with 571 additions and 5 deletions.
6 changes: 5 additions & 1 deletion components/table/select.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useState, useCallback } from 'react'
import { Select as DesignSelect } from '@oacore/design'
import escapeString from 'escape-string-regexp'

const Select = ({ id, options, label, placeholder, onOptionSelected }) => {
const [selectValue, setSelectValue] = useState('')
Expand All @@ -8,7 +9,10 @@ const Select = ({ id, options, label, placeholder, onOptionSelected }) => {
const getOptions = useCallback(
(searchTerm) =>
options.filter(
(el) => el.value.toLowerCase().search(searchTerm?.toLowerCase()) !== -1
(el) =>
el.value
.toLowerCase()
.search(escapeString(searchTerm?.toLowerCase())) !== -1
),

[options]
Expand Down
Loading

1 comment on commit ff43c26

@vercel
Copy link

@vercel vercel bot commented on ff43c26 Nov 25, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.