From a3c94ab910a1fb1efd717e6e1b628b87b5693e34 Mon Sep 17 00:00:00 2001 From: Russell Jackson Date: Wed, 12 Mar 2014 01:26:29 -0700 Subject: [PATCH] Fix Linux NFS exports pruning due to bad `sed` expression The mount id is a file path which will contain forward slashes. A previous attempt (although notably missing in the Linux host plugin) at fixing this used `String.gsub` to escape the forward slashes; however, the solution that eventually made its way into the 1.5 release uses `Regexp.escape` which doesn't escape forward slashes. The Ruby `Regexp.escape` method does not escape forward slashes because they are not RE meta-characters; their special meaning is specific to sed expressions as delimiters. To avoid the issue entirely, we can use an alternative delimiter by prefixing the address expression with a backslash with the desired delimiter character following. Use control character (ASCII code point `0x01`) as expression delimiter so it is very unlikely an identifier will have a conflicting character within it. --- plugins/hosts/linux/cap/nfs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hosts/linux/cap/nfs.rb b/plugins/hosts/linux/cap/nfs.rb index 4b9cd1b1f..ce1d0ba1b 100644 --- a/plugins/hosts/linux/cap/nfs.rb +++ b/plugins/hosts/linux/cap/nfs.rb @@ -94,7 +94,7 @@ module VagrantPlugins # Use sed to just strip out the block of code which was inserted # by Vagrant - system("sudo sed -r -e '/^# VAGRANT-BEGIN:( #{user})? #{id}/,/^# VAGRANT-END:( #{user})? #{id}/ d' -ibak /etc/exports") + system("sudo sed -r -e '\\\x01^# VAGRANT-BEGIN:( #{user})? #{id}\x01,\\\x01^# VAGRANT-END:( #{user})? #{id}\x01 d' -ibak /etc/exports") end def self.nfs_opts_setup(folders)