Edgewall Software
Modify

Opened 20 years ago

Closed 20 years ago

Last modified 19 years ago

#424 closed defect (fixed)

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

Reported by: Christopher Lenz Owned by: daniel
Priority: normal Milestone: 0.7.1
Component: version control/changeset view Version: 0.7
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

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 (0)

Change History (7)

comment:1 by Christopher Lenz, 20 years ago

Owner: changed from Christopher Lenz to daniel
Severity: normalminor
Status: newassigned

Fixed in [556].

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

comment:2 by Christopher Lenz, 20 years ago

Severity: minornormal
Summary: HTML diff strips single space characters at line beginsHTML 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.

comment:3 by Christopher Lenz, 20 years ago

Owner: changed from daniel to Christopher Lenz

comment:4 by Christopher Lenz, 20 years ago

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:

comment:5 by Christopher Lenz, 20 years ago

Owner: changed from Christopher Lenz to daniel

Daniel, can you port this to the 0.7 branch?

comment:6 by daniel, 20 years ago

Resolution: fixed
Status: assignedclosed

Merged in [561].

comment:7 by anonymous, 19 years ago

][ \=;kljkljkljkljkljkljl

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain daniel.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from daniel to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.