File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -51,13 +51,13 @@ class HTML < Basic
51
51
def set_color ( string , *colors )
52
52
if colors . all? { |color | color . is_a? ( Symbol ) || color . is_a? ( String ) }
53
53
html_colors = colors . map { |color | lookup_color ( color ) }
54
- "<span style=\" #{ html_colors . join ( '; ' ) } ;\" >#{ string } </span>"
54
+ "<span style=\" #{ html_colors . join ( '; ' ) } ;\" >#{ CGI . escapeHTML ( string ) } </span>"
55
55
else
56
56
color , bold = colors
57
57
html_color = self . class . const_get ( color . to_s . upcase ) if color . is_a? ( Symbol )
58
58
styles = [ html_color ]
59
59
styles << BOLD if bold
60
- "<span style=\" #{ styles . join ( '; ' ) } ;\" >#{ string } </span>"
60
+ "<span style=\" #{ styles . join ( '; ' ) } ;\" >#{ CGI . escapeHTML ( string ) } </span>"
61
61
end
62
62
end
63
63
Original file line number Diff line number Diff line change @@ -28,4 +28,14 @@ def shell
28
28
shell . say_status :conflict , "README" , :red
29
29
end
30
30
end
31
+
32
+ describe "#set_color" do
33
+ it "escapes HTML content when unsing the default colors" do
34
+ expect ( shell . set_color ( "<htmlcontent>" , :blue ) ) . to eq "<span style=\" color: blue;\" ><htmlcontent></span>"
35
+ end
36
+
37
+ it "escapes HTML content when not using the default colors" do
38
+ expect ( shell . set_color ( "<htmlcontent>" , [ :nocolor ] ) ) . to eq "<span style=\" ;\" ><htmlcontent></span>"
39
+ end
40
+ end
31
41
end
You can’t perform that action at this time.
0 commit comments