Skip to content

Commit

Permalink
Avoid escaping text in Popup module
Browse files Browse the repository at this point in the history
* It retains the previous behavior when no using the Richtext
  widget to avoid problems with text that was already escaped.
* When using Richtext widget, text is not escaped.
  • Loading branch information
imobachgs committed Feb 22, 2016
1 parent ada3a46 commit e971096
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
23 changes: 3 additions & 20 deletions library/general/src/modules/Popup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,13 @@ def popupLayoutInternalTypeWithLabel(headline, message, button_box, label, richt
button_box = deep_copy(button_box)
content = Empty()

body = richtext ? message : convert_to_plaintext(message)

rt = VWeight(
1,
VBox(
HSpacing(width),
HBox(
VSpacing(height),
# display the message in the widget "as is":
# escape all tags, replace new lines by <br> tag
RichText(body)
RichText(message)
)
)
)
Expand All @@ -95,7 +91,7 @@ def popupLayoutInternalTypeWithLabel(headline, message, button_box, label, richt
VBox(
Left(Heading(headline)),
VSpacing(0.2),
richtext ? rt : Left(Label(body)),
richtext ? rt : Left(Label(message)),
VSpacing(0.2),
!label.nil? && label != "" ? Label(Id(:label), label) : Empty()
)
Expand All @@ -104,7 +100,7 @@ def popupLayoutInternalTypeWithLabel(headline, message, button_box, label, richt
content = VBox(
VSpacing(0.4),
VBox(
richtext ? rt : VCenter(Label(body)),
richtext ? rt : VCenter(Label(message)),
VSpacing(0.2),
!label.nil? && label != "" ? Label(Id(:label), label) : Empty()
)
Expand Down Expand Up @@ -1910,19 +1906,6 @@ def ShowFile(headline, filename)
nil
end

private

# Adapt a message to be shown as plaintext in a Richtext widget
#
# * Escape tags
# * Replace "\n" by "<br>"
#
# @param [String] message Message to be converted
# @return [String] Converted message
def convert_to_plaintext(message)
String.EscapeTags(message).split("\n").join("<br>")
end

publish variable: :switch_to_richtext, type: "boolean"
publish variable: :too_many_lines, type: "integer"
publish function: :NoHeadline, type: "string ()"
Expand Down
12 changes: 6 additions & 6 deletions library/general/test/popup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,26 @@
describe ".Message" do
before { allow(ui).to receive(:OpenDialog) }

it "shows a popup with escaped tags" do
expect(subject).to receive(:RichText).with("&lt;h1&gt;Title&lt;/h1&gt;")
it "shows a popup without escaping tags" do
expect(subject).to receive(:RichText).with("<h1>Title</h1>")
subject.Message("<h1>Title</h1>")
end
end

describe ".Warning" do
before { allow(ui).to receive(:OpenDialog) }

it "shows a popup with escaped tags" do
expect(subject).to receive(:RichText).with("&lt;h1&gt;Title&lt;/h1&gt;")
it "shows a popup without escaping tags" do
expect(subject).to receive(:RichText).with("<h1>Title</h1>")
subject.Warning("<h1>Title</h1>")
end
end

describe ".Error" do
before { allow(ui).to receive(:OpenDialog) }

it "shows a popup with escaped tags" do
expect(subject).to receive(:RichText).with("&lt;h1&gt;Title&lt;/h1&gt;")
it "shows a popup without escaping tags" do
expect(subject).to receive(:RichText).with("<h1>Title</h1>")
subject.Error("<h1>Title</h1>")
end
end
Expand Down

0 comments on commit e971096

Please sign in to comment.