trekhleb / covid-19

šŸ“ˆ Coronavirus (COVID-19) dashboard to show the dynamics of Š”oronavirus distribution per country

Home Page:https://trekhleb.dev/covid-19/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unescaped user input

kylegrover opened this issue Ā· comments

typing ie / or + into the 'Search country' field crashes the app
problem occurs @ index.js:372 new RegExp(countrySearchQuery.trim(), 'i')

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
suggests this code

function escapeRegExp(string){
  return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}

Very good point! Thanks @kylegrover. It should be fixed now.