diff --git a/plugins/synced_folders/rsync/helper.rb b/plugins/synced_folders/rsync/helper.rb index c99a9dff2..6ee1dea92 100644 --- a/plugins/synced_folders/rsync/helper.rb +++ b/plugins/synced_folders/rsync/helper.rb @@ -27,18 +27,15 @@ module VagrantPlugins if exclude.start_with?("/") start_anchor = true - exclude = exclude[1..-1] end - exclude = "#{exclude}/" if !exclude.end_with?("/") - exclude = "^#{exclude}" - exclude += ".*" if !start_anchor + exclude = "#{exclude}/" if !exclude.end_with?("/") if start_anchor + exclude = "^#{exclude}" if start_anchor + exclude += ".*" if (!start_anchor && !exclude.end_with?("*")) # This is not an ideal solution, but it's a start. We can improve and # keep unit tests passing in the future. exclude = exclude.gsub("**", "|||GLOBAL|||") - exclude = exclude.gsub("*", "|||PATH|||") - exclude = exclude.gsub("|||PATH|||", "[^/]*") exclude = exclude.gsub("|||GLOBAL|||", ".*") Regexp.new(exclude) diff --git a/test/unit/plugins/synced_folders/rsync/helper_test.rb b/test/unit/plugins/synced_folders/rsync/helper_test.rb index 67472f384..44c3d30bd 100644 --- a/test/unit/plugins/synced_folders/rsync/helper_test.rb +++ b/test/unit/plugins/synced_folders/rsync/helper_test.rb @@ -32,23 +32,31 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do let(:path) { "/foo/bar" } it "converts a directory match" do + expected_regex = /foo\/.*/ expect(described_class.exclude_to_regexp("foo/")). - to eq(/^foo\/.[^\/]*/) + to eq(/foo\/.*/) + expect(path).to match(expected_regex) end it "converts the start anchor" do + expected_regex = /^\/foo\// expect(described_class.exclude_to_regexp("/foo")). - to eq(/^foo\//) + to eq(expected_regex) + expect(path).to match(expected_regex) end it "converts the **" do + expected_regex = /fo.*o.*/ expect(described_class.exclude_to_regexp("fo**o")). - to eq(/^fo.*o\/.[^\/]*/) + to eq(expected_regex) + expect(path).to match(expected_regex) end it "converts the *" do + expected_regex = /fo*o.*/ expect(described_class.exclude_to_regexp("fo*o")). - to eq(/^fo[^\/]*o\/.[^\/]*/) + to eq(expected_regex) + expect(path).to match(expected_regex) end end