Commit 130eedc4 by Hugo Häggmark

Found another input that was tied to a regexp

parent 5388541f
import React, { ChangeEvent, forwardRef } from 'react'; import React, { forwardRef } from 'react';
const specialChars = ['(', '[', '{', '}', ']', ')', '|', '*', '+', '-', '.', '?', '<', '>', '#', '&', '^', '$']; const specialChars = ['(', '[', '{', '}', ']', ')', '|', '*', '+', '-', '.', '?', '<', '>', '#', '&', '^', '$'];
export const escapeStringForRegex = (event: ChangeEvent<HTMLInputElement>) => { export const escapeStringForRegex = (value: string) => {
const value = event.target.value;
if (!value) { if (!value) {
return value; return value;
} }
...@@ -42,7 +41,7 @@ export const RegExpSafeInput = forwardRef<HTMLInputElement, Props>((props, ref) ...@@ -42,7 +41,7 @@ export const RegExpSafeInput = forwardRef<HTMLInputElement, Props>((props, ref)
type="text" type="text"
className={props.className} className={props.className}
value={unEscapeStringFromRegex(props.value)} value={unEscapeStringFromRegex(props.value)}
onChange={event => props.onChange(escapeStringForRegex(event))} onChange={event => props.onChange(escapeStringForRegex(event.target.value))}
placeholder={props.placeholder ? props.placeholder : null} placeholder={props.placeholder ? props.placeholder : null}
/> />
)); ));
...@@ -5,6 +5,7 @@ import AsyncSelect from '@torkelo/react-select/lib/Async'; ...@@ -5,6 +5,7 @@ import AsyncSelect from '@torkelo/react-select/lib/Async';
import { TagOption } from './TagOption'; import { TagOption } from './TagOption';
import { TagBadge } from './TagBadge'; import { TagBadge } from './TagBadge';
import { components } from '@torkelo/react-select'; import { components } from '@torkelo/react-select';
import { escapeStringForRegex } from '../RegExpSafeInput/RegExpSafeInput';
export interface Props { export interface Props {
tags: string[]; tags: string[];
...@@ -51,7 +52,7 @@ export class TagFilter extends React.Component<Props, any> { ...@@ -51,7 +52,7 @@ export class TagFilter extends React.Component<Props, any> {
value: tags, value: tags,
styles: resetSelectStyles(), styles: resetSelectStyles(),
filterOption: (option, searchQuery) => { filterOption: (option, searchQuery) => {
const regex = RegExp(searchQuery, 'i'); const regex = RegExp(escapeStringForRegex(searchQuery), 'i');
return regex.test(option.value); return regex.test(option.value);
}, },
components: { components: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment