nearform / udaru

Open source Access Manager for node.js
https://nearform.github.io/udaru
MIT License
124 stars 19 forks source link

tsquery characters #541

Closed cianfoley-nearform closed 6 years ago

cianfoley-nearform commented 6 years ago

we have issue with team names having characters that need escaping prior to input e.g. : is reserved to qualify parts of the search with weightings, substring search and so on...

proposing this solution...

query.replace(/'/g, "''").replace(/\\/g, '\\\\').split(' ').join("':* & '") + "':*"

basically encapsulating each component part of string with quotes (this handles characters like : which are reserved) and then anding together, then escaping quotes within each string and backslashes...

looks a bit messy

I want to put this in utils and use it centrally for each search tsquery...

posting here before PRing

@dberesford @mihaidma

cianfoley-nearform commented 6 years ago

pr approved