scimitar 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8c16f7606590c342b819bc9e8f44111e451897ca670d90321ba285ac259e892
4
- data.tar.gz: db95329ce66a59ce500cb4c03b1bfbf5cac2b72b1604b72916070f647a8d6914
3
+ metadata.gz: 6f44cfce4b49e3f386b14081151dc38bf5bf857939fefbad36b507770d1de2e9
4
+ data.tar.gz: ba7fe68d41eb204a84f71e23931ed85a497645671170994043abab4e1b7dba73
5
5
  SHA512:
6
- metadata.gz: f204ce89ecad62257ac04f8fe648abaa1f9a5822b7abc3597fe2ee27758a120e8a6e3f46982fbff099af80558f9bd5aee8246a3c396e9809973edd2a761d3cfb
7
- data.tar.gz: 8da76599bc3740e9c3f72daebc427342f7d2112a0f750aae4c51594e53c7dcc76f950d0b18cb21e3f93edcda767647713c3169a62684a43b1cb7d94e939f44bf
6
+ metadata.gz: 1b267f42755f9fc94280ea7c84d08762056e95dd967a6d17535cefd9275e04f60e3abc1a20a7849ab7f3bbd8fa508047586f23cb33ed6d7bec56bc6c2d3fcf7d
7
+ data.tar.gz: facdf0cb0566d0b323181abb0d4707c2036f85b2f958f29dc0df0471a6244595c6147a7887895b7a96689288edea3c684cbf3d32c7119959ff70c28abc610d9e
@@ -945,12 +945,27 @@ module Scimitar
945
945
  # Happily throws exceptions if data is not as expected / required.
946
946
  #
947
947
  def all_matching_filter(filter:, within_array:, &block)
948
- filter_components = filter.split(' ')
949
- raise "Unsupported matcher #{filter.inspect}" unless filter_components.size == 3 && filter_components[1].downcase == 'eq'
948
+ filter_components = filter.split(' ', 3)
950
949
 
951
950
  attribute = filter_components[0]
951
+ operator = filter_components[1]
952
952
  value = filter_components[2]
953
- value = value[1..-2] if value.start_with?('"') && value.end_with?('"')
953
+
954
+ # Quoted value includes closing quote but has data afterwards?
955
+ # Bad; implies extra conditions, e.g. '...eq "one two" and..." or
956
+ # just junk data.
957
+ #
958
+ # Value is *not* quoted but contains a space? Means there must be
959
+ # again either extra conditions or trailing junk data.
960
+ #
961
+ raise "Unsupported matcher #{filter.inspect}" if (
962
+ filter_components.size != 3 ||
963
+ operator.downcase != 'eq' ||
964
+ value.strip.match?(/\".+[^\\]\".+/) || # Literal '"', any data, no-backslash-then-literal (unescaped) '"', more data
965
+ (!value.start_with?('"') && value.strip.include?(' '))
966
+ )
967
+
968
+ value = value[1..-2] if value.start_with?('"') && value.end_with?('"')
954
969
 
955
970
  within_array.each.with_index do | hash, index |
956
971
  matched = hash.key?(attribute) && hash[attribute]&.to_s == value&.to_s
@@ -3,7 +3,7 @@ module Scimitar
3
3
  # Gem version. If this changes, be sure to re-run "bundle install" or
4
4
  # "bundle update".
5
5
  #
6
- VERSION = '1.0.2'
6
+ VERSION = '1.0.3'
7
7
 
8
8
  # Date for VERSION. If this changes, be sure to re-run "bundle install"
9
9
  # or "bundle update".
@@ -522,6 +522,22 @@ RSpec.describe Scimitar::Resources::Mixin do
522
522
  end.to raise_error(RuntimeError)
523
523
  end
524
524
 
525
+ it 'complaints about unsupported multiple operators, handling value spaces' do
526
+ expect do
527
+ @instance.send(:all_matching_filter, filter: 'type eq "work with spaces" and primary pr', within_array: []) do
528
+ fail # Block should never be called!
529
+ end
530
+ end.to raise_error(RuntimeError)
531
+ end
532
+
533
+ it 'complaints about unquoted values with spaces' do
534
+ expect do
535
+ @instance.send(:all_matching_filter, filter: 'type eq work with spaces', within_array: []) do
536
+ fail # Block should never be called!
537
+ end
538
+ end.to raise_error(RuntimeError)
539
+ end
540
+
525
541
  it 'calls block with matches' do
526
542
  array = [
527
543
  {
@@ -565,6 +581,10 @@ RSpec.describe Scimitar::Resources::Mixin do
565
581
  {
566
582
  'type' => 'work"',
567
583
  'value' => 'work_trailing_dquote@test.com'
584
+ },
585
+ {
586
+ 'type' => 'spaced',
587
+ 'value' => 'value with spaces'
568
588
  }
569
589
  ]
570
590
 
@@ -585,7 +605,12 @@ RSpec.describe Scimitar::Resources::Mixin do
585
605
  expect(matched_hash['value']).to eql('boolean@test.com')
586
606
  end
587
607
 
588
- expect(call_count).to eql(3)
608
+ @instance.send(:all_matching_filter, filter: 'value eq "value with spaces"', within_array: array) do |matched_hash, index|
609
+ call_count += 1
610
+ expect(matched_hash['type']).to eql('spaced')
611
+ end
612
+
613
+ expect(call_count).to eql(4)
589
614
  end
590
615
  end # "context '#all_matching_filter' do"
591
616
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scimitar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - RIP Global