Update UI to properly retain newlines when adding prefix

When using a Prefixed UI instance prevent new line characters from
being removed when adding prefix formatting to output messages.

Fixes #11044
This commit is contained in:
Chris Roberts 2019-10-14 16:56:40 -07:00
parent d2914a85ee
commit 783f5fc65d
2 changed files with 14 additions and 4 deletions

View File

@ -329,10 +329,12 @@ module Vagrant
target = opts[:target] if opts.key?(:target)
target = "#{target}:" if target != ""
# Get the lines. The first default is because if the message
# is an empty string, then we want to still use the empty string.
lines = [message]
lines = message.split("\n") if message != ""
lines = [].tap do |l|
message.scan(/(.*?)(\n|$)/).each do |m|
l << m.first if m.first != "" || (m.first == "" && m.last == "\n")
end
end
lines << "" if message.end_with?("\n")
# Otherwise, make sure to prefix every line properly
lines.map do |line|

View File

@ -406,4 +406,12 @@ describe Vagrant::UI::Prefixed do
subject.output("foo", target: "bar")
end
end
describe "#format_message" do
it "should return the same number of new lines as given" do
["no new line", "one\nnew line", "two\nnew lines\n", "three\nnew lines\n\n"].each do |msg|
expect(subject.format_message(:detail, msg).count("\n")).to eq(msg.count("\n"))
end
end
end
end