pelias / placeholder

stand-alone coarse geocoder
https://placeholder.demo.geocode.earth
MIT License
313 stars 35 forks source link

improve quoting of token count query #223

Closed missinglink closed 2 years ago

missinglink commented 2 years ago

There appears to be a bug when using the token count query with reserved tokens such as #. This PR wraps that query in the same way we wrap the other ones to it can accept any characters as input.

npm run cli -- 'san fran #1'

> pelias-placeholder@0.0.0-development cli
> node cmd/cli.js "san fran #1"

san fran #1

/Users/peter/code/pelias/placeholder/lib/Queries.js:151
    return stmt.get(token).cnt;
                ^
SqliteError: fts5: syntax error near "#"
    at /Users/peter/code/pelias/placeholder/lib/Queries.js:151:17
    at Array.map (<anonymous>)
orangejulius commented 2 years ago

Ah yeah, much better!

Pretty wild the hoops you have to jump through to properly quote, my initial version of this just removed the characters that the query didn't like 😆.

missinglink commented 2 years ago

Yeah its weird, MATCH expects an FTS query as its right operand, and that query language has its own quoting rules.

On top of all that are the quoting rules when binding query variables, it all ends up a bit convoluted, I remember looking into it a while back and I'm pretty confident that this is correct, despite being a bit weird looking.