Skip to content
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

strict field regex #16

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html

### Breaking changes

- only parse strings with single colons as fields

### Compatible changes


Expand Down
4 changes: 2 additions & 2 deletions lib/minidusen/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ class Parser

class CannotParse < StandardError; end

TEXT_QUERY = /(?:(\-)?"([^"]+)"|(\-)?([\S]+))/
FIELD_QUERY = /(?:\s|^|(\-))(\w+)\:#{TEXT_QUERY}/
TEXT_QUERY = /(?:(-)?"([^"]+)"|(-)?(\S+))/
FIELD_QUERY = /(?:\s|^|(-))(\w+):(?!:)#{TEXT_QUERY}/

class << self

Expand Down
9 changes: 9 additions & 0 deletions spec/minidusen/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@
query[0].exclude.should == true
end

it 'only parses single colons as fields' do
query = Minidusen::Parser.parse('filetype:docx Namespaced::Klass')
expect(query.size).to eq(2)
expect(query[0].field).to eq('filetype')
expect(query[0].value).to eq('docx')
expect(query[1].field).to eq('text')
expect(query[1].value).to eq('Namespaced::Klass')
end

it 'should ignore invalid utf-8 byte sequences' do
term_with_invalid_byte_sequence = "word\255".force_encoding('UTF-8')

Expand Down
Loading