-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Really odd error report from an innocuous search string #222
Comments
Follow-up: running this in development, I can see that the error is coming from https://github.com/wvanbergen/scoped_search/blob/master/lib/scoped_search/query_builder.rb#L476 definitively. Screwing around with the input, I can determine that the breaking point is when the word |
I was able to work around this by adding a before_action to load and process the query term:
I searched through the Wiki and read through a lot of the code, and while I was able to find the keywords in the Tokenizer module, I was not able to find any way to configure Scoped Search to not act on those. It seems determined to interpret Wrapping the user input as a phrase works around this, but it feels more as though the casual use of this gem would not be to start slinging SQL operations around in a text search field. Let that be an expert option that you enable by choice, so you know to explain to your users that they must know what all of the fieldnames are before they start using the common English word 'has' followed by literally any other word as their search term. |
You're mostly right about where this comes from. This gem provides a query language (and enables you to search using this language),
Correct, there's no way to disable it as that would mean disabling a part of the query language.
Correct,
Just bear in mind that the semantics of searching for
If you really only want to search for exactly what the user passed in, then scoped_search might be too big of a hammer. |
Thanks very much. I totally agree about the hammer bit. I reached for it because I was in a hurry, and I didn't want to be completely irresponsible by just allowing a SQL injection. I will do some more searching for a simpler solution. I really do like what you've built here, and can see it has great value where all of its features are needed. I do realize that the phrase search is limiting the possible matches. Since the implementation here actually didn't anticipate someone entering an entire phrase (it was used for a search by name feature, triggered on keyup after the third character) the resulting error came out of left field from my perspective. But given an infinite universe of users, after four or five months someone decided to paste a phrase into the field... Thanks very much for your feedback and for making this gem. |
One more suggestion here: would it be possible to use ActiveRecord's One last thought: could there be a specific error that means "tried to search on a column, but there's no matching column"? That way an end-user could trap that error and decide what to do. The current QueryNotSupported is not unique to this case, and the only way to discern the source of the error state would be by filtering on the message text. |
In the situation where
Sure, that's a good idea. In case you do stick with scoped_search in the end, would you be willing to take a stab at it? |
Yes and yes. I will post here when I have something for either of these angles. I do like the gem very much.
Walter
… On Jul 10, 2024, at 5:03 AM, Adam Růžička ***@***.***> wrote:
One more suggestion here: would it be possible to use ActiveRecord's column_names list to flavor which tokens are considered to mean that you are in the presence of an expert user, rather than an unknowing use of the keywords?
In the situation where foo is a searchable column and bar is not, I'm a little uneasy about the idea of searching for has foo and has bar doing different things. How about instead of doing this, we'd rename the has operator to has? to signify it is something special? It would be more in line with other prefix unary operators (set? and null?) and hopefully it would be harder to trigger by accident.
One last thought: could there be a specific error that means "tried to search on a column, but there's no matching column"?
Sure, that's a good idea. In case you do stick with scoped_search in the end, would you be willing to take a stab at it?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.
|
@adamruzicka could I get a little hint on the test setup? I'm trying to tack on to the existing query builder spec like so:
but I am getting
I've tried a number of different variations on this setup, with and without the ? placeholder, and while I can see that I am getting the correct AST type from the definition, nothing I do seems to give it the I am certain this is down to the way I am setting up the stubs here, as I am just cribbing from the other tests in this file as best I can understand them. Any suggestions would be appreciated. Walter |
Oof, this is tricky. I tried explaining that some time ago in here #217 (comment) , maybe it will give you a bit of an insight about what's going on.
Spot on, by stubbing
Another option would be having this with less stubbing as an integration test and then making assertions about the sql query that gets generated by calling |
@adamruzicka when you have a chance, #223 needs a button pressed from you. My first run through exposed a cross-db issue in my test, which I believe the latest push has resolved. |
Environment:
scoped_search
(4.1.11)mysql2
0.5.4I have a
scoped_search
set on a single column, and the user entered a long-ish query string:Which resulted in this error report:
That might be coming from https://github.com/wvanbergen/scoped_search/blob/master/lib/scoped_search/query_builder.rb#L476 or https://github.com/wvanbergen/scoped_search/blob/master/lib/scoped_search/query_builder.rb#L509, but I can't see why either would be relevant. Is there anything about the words in the request such that
a
might be interpreted as being a column name?The model has this definition:
(
search_name
is just a downcased and simplified version of the name, created withparameterize.gsub('-', ' ')
)The controller uses it here:
I just can't see why Scoped Search was considering part of the query string as a mention of a column. There were no control characters or quotes in the input. Can anyone see something I have missed here?
The text was updated successfully, but these errors were encountered: