Defect #17809

wrong syntax highlighting "---" header and "--" footer of git diff

Added by Tobias Fischer about 6 years ago. Updated 7 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:UI
Target version:-
Resolution: Affected version:2.5.2

Description

Rendering of patches adds an additional "deletion" line for the following (standard) diff syntax:

Whereas the "deletion" of line 22 in the screenshot isn't part of the changeset at all:

From 9b1992fe9db52e1df90a6a963a686cd2cf20e706 Mon Sep 17 00:00:00 2001
From: Tobias Fischer
Date: Sat, 6 Sep 2014 12:22:02 +0200
Subject: [PATCH]  Additional view hook "body_top" 

In the same way as "view_layouts_base_body_bottom" exists...
---
 app/views/layouts/base.html.erb | 1 +
 1 file changed, 1 insertion(+)

diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb
index 99ad13f..45ef5bd 100644
--- a/app/views/layouts/base.html.erb
+++ b/app/views/layouts/base.html.erb
@@ -16,6 +16,7 @@
 <%= yield :header_tags -%>
 </head>
 <body class="<%=h body_css_classes %>">
+<%= call_hook :view_layouts_base_body_top %>
 <div id="wrapper">
 <div id="wrapper2">
 <div id="wrapper3">
-- 
1.8.5.2 (Apple Git-48)

And also this diff gets wrong syntax highlighting for the meta-lines "---" and "-- "

So I would expect the line 22 not to be rendered at all and an the syntax highlighting, there should be no highlighting for "---" and "-- "

patch_screenshot.png (28 KB) Tobias Fischer, 2014-09-06 12:31

3.4.png (33.3 KB) Toshi MARUYAMA, 2020-04-26 17:13

4.1.png (30 KB) Toshi MARUYAMA, 2020-04-26 17:13

History

#1 Updated by Toshi MARUYAMA about 6 years ago

  • Subject changed from rendering of patch files (attachments) has a bug in reading the patch/diff format to rendering extra "--" footer of git patch

#2 Updated by Toshi MARUYAMA about 6 years ago

Tobias Fischer wrote:

the following (standard) diff syntax:

It is not standard diff format.
It is git additional footer.
Mercurial patch does not have such footer.
source:tags/2.5.2/test/fixtures/diffs/issue-12641-ja.diff

#3 Updated by Toshi MARUYAMA about 6 years ago

  • Subject changed from rendering extra "--" footer of git patch to rendering extra "---" header and "--" footer of git patch

#4 Updated by Tobias Fischer about 6 years ago

Toshi MARUYAMA wrote:

Tobias Fischer wrote:

the following (standard) diff syntax:

It is not standard diff format.
It is git additional footer.
Mercurial patch does not have such footer.

Oh, okay, sorry then.
But anyways, the "deletion" line shouldn't be rendered for git diffs then ;-)

#5 Updated by Go MAEDA 8 months ago

It can be fixed with the following code:

diff --git a/lib/redmine/unified_diff.rb b/lib/redmine/unified_diff.rb
index 67292cf0f..5c258b564 100644
--- a/lib/redmine/unified_diff.rb
+++ b/lib/redmine/unified_diff.rb
@@ -78,7 +78,7 @@ module Redmine
           @parsing = true
         end
       else
-        if %r{^[^\+\-\s@\\]}.match?(line)
+        if /^([^\+\-\s@\\]|-- $)/.match?(line)
           @parsing = false
           return false
         elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/

#6 Updated by Toshi MARUYAMA 7 months ago

  • Category changed from Attachments to UI

#7 Updated by Toshi MARUYAMA 7 months ago

Go MAEDA wrote:

It can be fixed with the following code:

No.

I have created new #33357.

#8 Updated by Toshi MARUYAMA 7 months ago

  • File 3.4.png added
  • File 4.1.png added
  • Subject changed from rendering extra "---" header and "--" footer of git patch to wrong syntax highlighting "---" header and "--" footer of git diff
  • Status changed from New to Closed

3.4

4.1

#9 Updated by Toshi MARUYAMA 7 months ago

Toshi MARUYAMA wrote:

Go MAEDA wrote:

It can be fixed with the following code:

No.

I have created new #33357.

I have written reason at #33357#note-2.

Also available in: Atom PDF