Edgewall Software

Ticket #424 (closed defect: fixed)

Opened 5 years ago

Last modified 4 years ago

HTML diff strips space character when line indentation uses an odd number of spaces

Reported by: cmlenz Owned by: daniel
Priority: normal Milestone: 0.7.1
Component: version control/changeset view Version: 0.7
Severity: normal Keywords:
Cc:

Description

If a line contains a single space character at the beginning of a line, that space is stripped from the HTML diff view, effectively putting the character after the space directly at the beginning of the line.

For an example, examine the HTML diff of [555]. In the diff for changeset.cs, the <tr class="..."> elements are actually indented by a single space in the source.

Attachments

Change History

Changed 5 years ago by cmlenz

  • owner changed from cmlenz to daniel
  • status changed from new to assigned
  • severity changed from normal to minor

Fixed in [556].

Need someone with more karma to port this fix to 0.7-stable.

Changed 5 years ago by cmlenz

  • severity changed from minor to normal
  • summary changed from HTML diff strips single space characters at line begins to HTML diff strips space character when line indentation uses an odd number of spaces

The problem is actually somewhat broader than originally identified. For every line that is indented by an odd number of spaces, one space is dropped from the HTML diff display. While this is most visible for indentation, it will also be a problem for multiple spaces in sequence anywhere on a line.

This is because the code in Changeset.py explicitly replaces all occurences of two space characters in sequence by &nbsp; and a space.

So [556] only fixes a subset of the problem, namely when the lines are indented by exactly one space.

Changed 5 years ago by cmlenz

  • owner changed from daniel to cmlenz

Changed 5 years ago by cmlenz

Okay, I've got a real fix for this issue in trunk now (changeset [559]).

Here's a patch for 0.7-stable, assuming that [556] wasn't ported yet:

Index: trac/Changeset.py
===================================================================
--- trac/Changeset.py	(revision 559)
+++ trac/Changeset.py	(working copy)
@@ -30,7 +30,7 @@
 
 line_re = re.compile('@@ [+-]([0-9]+),([0-9]+) [+-]([0-9]+),([0-9]+) @@')
 header_re = re.compile('header ([^\|]+) \| ([^\|]+) redaeh')
-space_re = re.compile('  ')
+space_re = re.compile(' ( +)|^ ')
 
 class DiffColorizer:
     def __init__(self, hdf, prefix='changeset.diff'):
@@ -83,7 +83,9 @@
             return
         ttype = text[0]
         text = text[1:]
-        text = space_re.sub('&nbsp; ', text.expandtabs(8))
+        text = space_re.sub(lambda m:
+            len(m.group(0)) / 2 * '&nbsp; ' + len(m.group(0)) % 2 * '&nbsp;',
+            text.expandtabs(8))
         if ttype == self.ttype:
             self.block.append(text)
         else:

Changed 5 years ago by cmlenz

  • owner changed from cmlenz to daniel

Daniel, can you port this to the 0.7 branch?

Changed 5 years ago by daniel

  • status changed from assigned to closed
  • resolution set to fixed

Merged in [561].

Changed 4 years ago by anonymous

][ \=;kljkljkljkljkljkljl

Add/Change #424 (HTML diff strips space character when line indentation uses an odd number of spaces)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
to The owner will change from daniel. Next status will be 'closed'
 
Note: See TracTickets for help on using tickets.