From 281643a1bfd6f4da88a278bfce20133c80105de5 Mon Sep 17 00:00:00 2001
From: Marin Jankovski <marin@gitlab.com>
Date: Fri, 23 May 2014 12:58:34 +0200
Subject: [PATCH] Add feature spec.

---
 features/project/issues/issues.feature |  6 ++++++
 features/steps/project/issues.rb       | 12 ++++++++++++
 lib/redcarpet/render/gitlab_html.rb    |  6 +++---
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/features/project/issues/issues.feature b/features/project/issues/issues.feature
index c5311544efa5..191e8dcbe7fd 100644
--- a/features/project/issues/issues.feature
+++ b/features/project/issues/issues.feature
@@ -68,6 +68,12 @@ Feature: Project Issues
     And I leave a comment with a header containing "Comment with a header"
     Then The comment with the header should not have an ID
 
+  @javascript
+  Scenario: Blocks inside comments should not build relative links
+    Given I visit issue page "Release 0.4"
+    And I leave a comment with code block
+    Then The code block should be unchanged
+
   Scenario: Issues on empty project
     Given empty project "Empty Project"
     When I visit empty project page
diff --git a/features/steps/project/issues.rb b/features/steps/project/issues.rb
index d1f3ba25a21b..d0b4aa6e0800 100644
--- a/features/steps/project/issues.rb
+++ b/features/steps/project/issues.rb
@@ -163,4 +163,16 @@ class ProjectIssues < Spinach::FeatureSteps
     project = Project.find_by(name: 'Empty Project')
     visit project_issues_path(project)
   end
+
+  step 'I leave a comment with code block' do
+    within(".js-main-target-form") do
+      fill_in "note[note]", with: "```\nCommand [1]: /usr/local/bin/git , see [text](doc/text)\n```"
+      click_button "Add Comment"
+      sleep 0.05
+    end
+  end
+
+  step 'The code block should be unchanged' do
+    page.should have_content("```\nCommand [1]: /usr/local/bin/git , see [text](doc/text)\n```")
+  end
 end
diff --git a/lib/redcarpet/render/gitlab_html.rb b/lib/redcarpet/render/gitlab_html.rb
index 29bf42e76264..bb225f1acd8a 100644
--- a/lib/redcarpet/render/gitlab_html.rb
+++ b/lib/redcarpet/render/gitlab_html.rb
@@ -6,8 +6,6 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
   def initialize(template, options = {})
     @template = template
     @project = @template.instance_variable_get("@project")
-    @ref = @template.instance_variable_get("@ref")
-    @request_path = @template.instance_variable_get("@path")
     @options = options.dup
     super options
   end
@@ -46,7 +44,9 @@ def header(text, level)
   end
 
   def postprocess(full_document)
-    full_document = h.create_relative_links(full_document)
+    unless @template.instance_variable_get("@project_wiki") || @project.nil?
+      full_document = h.create_relative_links(full_document)
+    end
     h.gfm(full_document)
   end
 end
-- 
GitLab