Skip to content

Commit 068d759

Browse files
committed
Wrap all string autocomplete values in quotes, not just those containing whitespace
1 parent 3c431df commit 068d759

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

CHANGELOG.rdoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Please add an entry to the "Unreleased changes" section in your pull requests.
66

77
=== Unreleased changes
88

9+
- Autocomplete now wraps all strings in quotes, not just those containing whitespace
10+
911
=== Version 4.1.10
1012

1113
- Fix querying through associations in Rails 6.1 (undefined method join_keys) (#201)

lib/scoped_search/auto_complete_builder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def complete_value_from_db(field, special_values, val)
215215
.distinct
216216
.map(&field.field)
217217
.compact
218-
.map { |v| v.to_s =~ /\s/ ? "\"#{v.gsub('"', '\"')}\"" : v }
218+
.map { |v| v.is_a?(String) ? "\"#{v.gsub('"', '\"')}\"" : v }
219219
end
220220

221221
def completer_scope(field)

spec/integration/auto_complete_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ class ::Infoo < ::Foo
169169
end
170170

171171
it "should complete values should contain baz" do
172-
Foo.complete_for('explicit = ').should contain('explicit = baz')
172+
Foo.complete_for('explicit = ').should contain('explicit = "baz"')
173173
end
174174

175-
it "should complete values with quotes where required" do
175+
it "should complete values with quotes where value is a string" do
176176
Foo.complete_for('alias = ').should contain('alias = "temp \"2\""')
177177
end
178178
end

0 commit comments

Comments
 (0)