Emoji plus admin area cause 500 error
orangejulius opened this issue · comments
Here's a "fun one":
Queries that combine an emoji and an admin area name result in a 500 error.
Here's an example:
/v1/autocomplete?text=new york, ❤️usa
Here's the error log:
Error: invalid value, value must be valid js Variable
at Variable.set (/Users/julian/repos/pelias/api/node_modules/pelias-query/lib/Variable.js:25:11)
at /Users/julian/repos/pelias/api/query/view/admin_multi_match_first.js:41:36
at Array.forEach (<anonymous>)
at /Users/julian/repos/pelias/api/query/view/admin_multi_match_first.js:39:17
at /Users/julian/repos/pelias/api/node_modules/pelias-query/layout/FilteredBooleanQuery.js:30:22
at Array.forEach (<anonymous>)
at Layout.render (/Users/julian/repos/pelias/api/node_modules/pelias-query/layout/FilteredBooleanQuery.js:28:17)
at generateQuery (/Users/julian/repos/pelias/api/query/autocomplete.js:196:17)
at controller (/Users/julian/repos/pelias/api/controller/search.js:30:27)
at Layer.handle [as handle_request] (/Users/julian/repos/pelias/api/node_modules/express/lib/router/layer.js:95:5)
While the error itself is generated in one of our query views, I believe the ultimate error is in sanitizer/_text_pelias_parser.js or somewhere earlier in processing the request.
The line linked above ends up operating on a list of tokens that looks like this: [ '', '️usa' ]
Ideally we'd ensure that these empty tokens are never generated.
While these inputs result in a 500 error, they don't crash the Pelias API. So this isn't the worst bug, but we prefer to fix any case where the Pelias API can generate a 500 error.
So weird, are we missing a Unicode range here?
https://github.com/pelias/api/blob/master/helper/unicode.js#L73