.*?}m) do |match|
"#{match}#{link_to("", url, html_options)[0..-5]}" # "".length +1
diff --git a/app/views/commits/_commit_box.html.haml b/app/views/commits/_commit_box.html.haml
index 506f4e09..572337de 100644
--- a/app/views/commits/_commit_box.html.haml
+++ b/app/views/commits/_commit_box.html.haml
@@ -11,10 +11,10 @@
= link_to tree_project_ref_path(@project, @commit.id), class: "browse-button primary grouped" do
%strong Browse Code ยป
%h3.commit-title.page_title
- = gfm @commit.title
+ = gfm escape_once(@commit.title)
- if @commit.description.present?
%pre.commit-description
- = gfm @commit.description
+ = gfm escape_once(@commit.description)
.commit-info
.row
.span4
diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb
index 0af33142..a6708a7a 100644
--- a/spec/helpers/gitlab_markdown_helper_spec.rb
+++ b/spec/helpers/gitlab_markdown_helper_spec.rb
@@ -292,11 +292,18 @@ describe GitlabMarkdownHelper do
actual = link_to_gfm("Fixed in #{commit.id}", commit_path, class: 'foo')
actual.should have_selector 'a.gfm.gfm-commit.foo'
end
+
+ it "escapes HTML passed in as the body" do
+ actual = "This is a test
- see ##{issues[0].id}"
+ link_to_gfm(actual, commit_path).should match('<h1>test</h1>')
+ end
end
describe "#markdown" do
it "should handle references in paragraphs" do
- markdown("\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit. #{commit.id} Nam pulvinar sapien eget odio adipiscing at faucibus orci vestibulum.\n").should == "Lorem ipsum dolor sit amet, consectetur adipiscing elit. #{link_to commit.id, project_commit_path(project, commit), title: commit.link_title, class: "gfm gfm-commit "} Nam pulvinar sapien eget odio adipiscing at faucibus orci vestibulum.
\n"
+ actual = "\n\nLorem ipsum dolor sit amet. #{commit.id} Nam pulvinar sapien eget.\n"
+ expected = project_commit_path(project, commit)
+ markdown(actual).should match(expected)
end
it "should handle references in headers" do