Move newlines out of quoted header and footer. Match carriage return along with newline in hosts file pattern.

This commit is contained in:
John Landis 2018-05-17 16:35:39 -04:00
parent bc8c0eb2e3
commit 7e434ecbb4
No known key found for this signature in database
GPG Key ID: 7AD7E30685E65491
1 changed files with 4 additions and 4 deletions

View File

@ -88,8 +88,8 @@ module VagrantPlugins
def update_content(file_content, resolving_machine, include_id, line_endings)
id = include_id ? " id: #{read_or_create_id}" : ""
header = "## vagrant-hostmanager-start#{id}\n"
footer = "## vagrant-hostmanager-end\n"
header = "## vagrant-hostmanager-start#{id}"
footer = "## vagrant-hostmanager-end"
body = get_machines
.map { |machine| get_hosts_file_entry(machine, resolving_machine) }
.join
@ -146,12 +146,12 @@ module VagrantPlugins
if body.empty?
block = "\n"
else
block = "\n\n" + header + body + footer + "\n"
block = "\n\n" + header + "\n" + body + footer + "\n\n"
end
# Pattern for finding existing block
header_pattern = Regexp.quote(header)
footer_pattern = Regexp.quote(footer)
pattern = Regexp.new("\n*#{header_pattern}.*?#{footer_pattern}\n*", Regexp::MULTILINE)
pattern = Regexp.new("[\r\n]*#{header_pattern}.*?#{footer_pattern}[\r\n]*", Regexp::MULTILINE)
# Replace existing block or append
content = old_content.match(pattern) ? old_content.sub(pattern, block) : old_content.rstrip + block
if line_endings == "crlf"