msfl_visitors 1.1.0.dev3 → 1.1.0.dev4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ec3bfda1d028fdcd4c4fb02eaf3e6a26c792e4b
4
- data.tar.gz: f1e1324598941df2d59dc3da9b80ef2f0a4e3710
3
+ metadata.gz: e7618102d9f99a0c0355ca268490a8f333726946
4
+ data.tar.gz: d53c6a5cafbb278a65a5be4d18342a9b90b492c5
5
5
  SHA512:
6
- metadata.gz: 8f910b468fefd6e905119c76e9fd7e9939490b37789ba76f9d1cc5a32d42d30a565f44aa32c0c72e8cd149ac10e4b564972f66536d9a59ba95aeca592744d408
7
- data.tar.gz: 9e621c0a5175d457c0dc0c63324ac229719442d01c9008a043ced18a41767c37597a5c14da68f710ed0cdf811c0820c07c17178a793b7820c2afc5a2ae67f0d3
6
+ metadata.gz: 69d662a60f191114662fa52b9cac362891d3e51f75405610fec3ebeb0be29a8bd47e8c8b4cdb34a18fa699203bcd115624479078f00e4102d3d639bf4e37b994
7
+ data.tar.gz: 8196994112628bf366eb554ffd291c95ce47a4b1bba99ec885eea7457a7717dfdc5a612a347b7a818fefa6e80380d7b746ea1833edd52a1613ef6ed29ec51c2f
@@ -73,7 +73,7 @@ module MSFLVisitors
73
73
  when Nodes::Field
74
74
  node.value.to_s
75
75
  when Nodes::Regex
76
- "/#{node.value}/"
76
+ "/#{Regexp.escape(node.value)}/"
77
77
  when Nodes::Word
78
78
  "\"#{node.value}\""
79
79
  when Nodes::Date, Nodes::Time
@@ -83,8 +83,8 @@ module MSFLVisitors
83
83
 
84
84
  when Nodes::Match
85
85
  if node.right.is_a? Nodes::Set
86
- regex = node.right.contents.map { |right_child| right_child.value.to_s }.join('|')
87
- "#{node.left.accept(visitor)} #{BINARY_OPERATORS[node.class]} #{MSFLVisitors::Nodes::Regex.new(regex).accept(visitor)}"
86
+ regex = '/' + node.right.contents.map { |right_child| MSFLVisitors::Nodes::Regex.new(right_child.value.to_s).accept(visitor)[1..-2] }.join('|') + '/'
87
+ "#{node.left.accept(visitor)} #{BINARY_OPERATORS[node.class]} #{regex}"
88
88
  else
89
89
  "#{node.left.accept(visitor)} #{BINARY_OPERATORS[node.class]} #{MSFLVisitors::Nodes::Regex.new(node.right.value.to_s).accept(visitor)}"
90
90
  end
@@ -159,8 +159,9 @@ module MSFLVisitors
159
159
 
160
160
  when Nodes::Match
161
161
  if node.right.is_a? Nodes::Set
162
- regex = node.right.contents.map { |right_child| right_child.value.to_s }.join('|')
163
- { agg_field_name: node.left.accept(visitor), operator: :match, test_value: MSFLVisitors::Nodes::Regex.new(regex).accept(visitor) }
162
+ regex = node.right.contents.map { |right_child| MSFLVisitors::Nodes::Regex.new(right_child.value.to_s).accept(visitor) }.join('|')
163
+ # regex = node.right.contents.map { |right_child| right_child.value.to_s }.join('|')
164
+ { agg_field_name: node.left.accept(visitor), operator: :match, test_value: regex }
164
165
  else
165
166
  { agg_field_name: node.left.accept(visitor), operator: :match, test_value: MSFLVisitors::Nodes::Regex.new(node.right.value.to_s).accept(visitor) }
166
167
  end
@@ -175,7 +176,7 @@ module MSFLVisitors
175
176
  Nodes::Dataset
176
177
  node.value
177
178
  when Nodes::Regex
178
- node.value.to_s
179
+ Regexp.escape(node.value.to_s)
179
180
 
180
181
  when Nodes::GreaterThan,
181
182
  Nodes::GreaterThanEqual,
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'msfl_visitors'
3
- s.version = '1.1.0.dev3'
3
+ s.version = '1.1.0.dev4'
4
4
  s.date = '2015-05-28'
5
5
  s.summary = "Convert MSFL to other forms"
6
6
  s.description = "Visitor pattern approach to converting MSFL to other forms."
@@ -683,6 +683,46 @@ describe MSFLVisitors::Visitor do
683
683
  end
684
684
  end
685
685
  end
686
+
687
+ describe "a Regex node" do
688
+
689
+ let(:regex) { "content" }
690
+
691
+ let(:node) { MSFLVisitors::Nodes::Regex.new regex }
692
+
693
+ it "returns: \"/content/\"" do
694
+ expect(result).to eq "/#{regex}/"
695
+ end
696
+
697
+ context "when using the Aggregations visitor" do
698
+
699
+ before { visitor.mode = :aggregations }
700
+
701
+ it "returns: the elasticsearch regular expression formatted string \"content\"" do
702
+ expect(result).to eq "#{regex}"
703
+ end
704
+ end
705
+
706
+ context "when the regex contains characters that require escaping" do
707
+
708
+ let(:regex) { 'this / needs to % {be,escaped} *. ^[or] | \else' }
709
+
710
+ let(:node) { MSFLVisitors::Nodes::Regex.new regex }
711
+
712
+ it "returns: '/this\\ /\\ needs\\ to\\ %\\ \\{be,escaped\\}\\ \\*\\.\\ \\^\\[or\\]\\ \\|\\ \\\\else/'" do
713
+ expect(result).to eq "/this\\ /\\ needs\\ to\\ %\\ \\{be,escaped\\}\\ \\*\\.\\ \\^\\[or\\]\\ \\|\\ \\\\else/"
714
+ end
715
+
716
+ context "when using the Aggregations visitor" do
717
+
718
+ before { visitor.mode = :aggregations }
719
+
720
+ it "returns: 'this\\ /\\ needs\\ to\\ %\\ \\{be,escaped\\}\\ \\*\\.\\ \\^\\[or\\]\\ \\|\\ \\\\else'" do
721
+ expect(result).to eq "this\\ /\\ needs\\ to\\ %\\ \\{be,escaped\\}\\ \\*\\.\\ \\^\\[or\\]\\ \\|\\ \\\\else"
722
+ end
723
+ end
724
+ end
725
+ end
686
726
  end
687
727
 
688
728
  describe "range value nodes" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msfl_visitors
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.dev3
4
+ version: 1.1.0.dev4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Courtland Caldwell