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 +4 -4
- data/app/models/scimitar/resources/mixin.rb +18 -3
- data/lib/scimitar/version.rb +1 -1
- data/spec/models/scimitar/resources/mixin_spec.rb +26 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f44cfce4b49e3f386b14081151dc38bf5bf857939fefbad36b507770d1de2e9
|
4
|
+
data.tar.gz: ba7fe68d41eb204a84f71e23931ed85a497645671170994043abab4e1b7dba73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
data/lib/scimitar/version.rb
CHANGED
@@ -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
|
-
|
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
|
|