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
Perform regexp escape on individual words before joining them #10
Conversation
@@ -73,8 +73,9 @@ def web_search | |||
end | |||
|
|||
def local_search | |||
query_regex = @query.join(' ').strip | |||
query_regex = Regexp.escape(query_regex) unless @use_regex | |||
query_regex = @query.reduce('') { |result, q| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too you could use an Array.new
, and result << (@use_regex ? q : Regexp.escape(q))
, then join
before stripping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -16,7 +16,7 @@ class Search < Command | |||
def self.options | |||
[ | |||
['--regex', 'Interpret the `QUERY` as a regular expression'], | |||
['--full', 'Search by name, summary, and description'], | |||
['--full', 'Search by name, summary, description and authors'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing Oxford comma
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I liked this fact :)
👍🏻 with specs and CHANGELOG |
dbc26c8
to
6dbef0c
Compare
Good to go from me 🚀 |
Perform regexp escape on individual words before joining them
To complete changes discussed in #8, we need to change Regexp escaping a little.
Specifically, current implementation performs escape after joining all query argument into a string. For example, while running
pod search --full network library
command, a string like"network\ library"
will be generated (they joined with space character, then whole string is escaped). This cause a problem inside SourcesManager. Because it needs to search for each query word individually and then return an intersection of individual results, it needs to split given query string to get individual words.Proposed implementation performs regexp escape on individual query arguments first, then joins escaped strings with space character.