Skip to content

Commit efe9697

Browse files
authored
Fixed the 500 and made bracketed literals parse as plain text #55 (#57)
Signed-off-by: Kai Wagner <kai.wagner@percona.com>
1 parent bd456f2 commit efe9697

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

app/controllers/topics_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ def latest_patchset
194194

195195
def search
196196
@search_query = params[:q].to_s.strip
197+
@viewing_since = viewing_since_param
198+
@new_topics_count = 0
197199

198200
if @search_query.blank?
199201
respond_to do |format|

app/services/search/query_parser.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class Grammar < Parslet::Parser
2727
(word_char >> (word_char | str(':') >> word_char.present?).repeat).as(:word)
2828
end
2929

30+
# Bracketed text (treated as plain text, not dependent conditions)
31+
rule(:bracketed_text) do
32+
str('[') >> (str(']').absent? >> any).repeat.as(:bracketed_content) >> str(']')
33+
end
34+
3035
# Selector keywords - IMPORTANT: longer strings must come before shorter prefixes
3136
# e.g., "reading" before "read", "messages_after" before "messages"
3237
rule(:selector_key) do
@@ -99,6 +104,7 @@ class Grammar < Parslet::Parser
99104
rule(:atom) do
100105
selector.as(:selector) |
101106
grouped |
107+
bracketed_text.as(:bracketed_text) |
102108
double_quoted.as(:quoted_text) |
103109
word.as(:plain_text)
104110
end
@@ -155,6 +161,14 @@ class Transform < Parslet::Transform
155161
{ type: :text, value: c.to_s, negated: false, quoted: true }
156162
end
157163

164+
# Bracketed text node
165+
rule(bracketed_text: { bracketed_content: simple(:c) }) do
166+
{ type: :text, value: "[#{c}]", negated: false, quoted: false }
167+
end
168+
rule(bracketed_text: { bracketed_content: sequence(:c) }) do
169+
{ type: :text, value: "[#{c.map(&:to_s).join}]", negated: false, quoted: false }
170+
end
171+
158172
# Selector with value and optional conditions
159173
rule(selector: { selector_key: simple(:k), selector_value: subtree(:v), conditions: subtree(:conds) }) do
160174
val = case v

spec/services/search/query_parser_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
expect(result[:negated]).to be false
1515
end
1616

17+
it 'parses bracketed text as plain text' do
18+
result = parser.parse('[proposal] plan')
19+
expect(result[:type]).to eq(:and)
20+
expect(result[:children].size).to eq(2)
21+
expect(result[:children][0][:type]).to eq(:text)
22+
expect(result[:children][0][:value]).to eq('[proposal]')
23+
expect(result[:children][1][:value]).to eq('plan')
24+
end
25+
1726
it 'parses multiple words as implicit AND' do
1827
result = parser.parse('postgresql vacuum')
1928
expect(result[:type]).to eq(:and)

0 commit comments

Comments
 (0)