#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 , 21 years ago
Owner: | changed from | to
---|---|
Severity: | normal → minor |
Status: | new → assigned |
comment:2 by , 21 years ago
Severity: | minor → normal |
---|---|
Summary: | HTML diff strips single space characters at line begins → 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
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 , 21 years ago
Owner: | changed from | to
---|
comment:4 by , 21 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(' ', text.expandtabs(8)) + text = space_re.sub(lambda m: + len(m.group(0)) / 2 * ' ' + len(m.group(0)) % 2 * ' ', + text.expandtabs(8)) if ttype == self.ttype: self.block.append(text) else:
Fixed in [556].
Need someone with more karma to port this fix to
0.7-stable
.