Skip to content

Commit

Permalink
fix: resolve inconsistency for filters containing curly brackets (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkalwa authored Feb 27, 2024
1 parent aee78ca commit 91c4210
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/graphiti/scoping/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ def parse_string_arrays(value, singular_filter)
# Find the quoted strings
quotes = value.scan(/{{.*?}}/)
# remove them from the rest
quotes.each { |q| value.gsub!(q, "") }
non_quotes = quotes.inject(value) { |v, q| v.gsub(q, "") }
# remove the quote characters from the quoted strings
quotes.each { |q| q.gsub!("{{", "").gsub!("}}", "") }
# merge everything back together into an array
value = if singular_filter
Array(value) + quotes
Array(non_quotes) + quotes
else
Array(value.split(",")) + quotes
Array(non_quotes.split(",")) + quotes
end
# remove any blanks that are left
value.reject! { |v| v.length.zero? }
Expand Down
14 changes: 14 additions & 0 deletions spec/filtering_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ def self.name
expect(records.map(&:id)).to eq([employee1.id])
end

context "retains filtering value" do
it "when value includes curly brackets" do
params[:filter] = {first_name: "{{John}}"}
records
expect(params[:filter]).to eq(first_name: "{{John}}")
end

it "when value does not include curly brackets" do
params[:filter] = {first_name: "John"}
records
expect(params[:filter]).to eq(first_name: "John")
end
end

context "when filter is type hash" do
before do
resource.filter :by_json, :hash do
Expand Down

0 comments on commit 91c4210

Please sign in to comment.