Opened 10 years ago

Closed 6 years ago

#1227 closed defect (fixed)

Problem with spaceless

Reported by: Simon Willison Owned by: adrian
Component: Template system Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The new spaceless tag introduced in [1968] is over-zealous. Consider the following example (taken from metafilter, where it is a common idiom):

<a href="http://www.carm.org/questions/rock.htm">Can God</a> <a href="http://www.str.org/site/News2?page=NewsArticle&id=5160">make a rock</a> <a href="http://www.godandscience.org/apologetics/rock.html">so heavy</a> <a href="http://www.simpsoncrazy.com/information/scripts/dabf11.shtml">that he</a> <a href="http://geocities.com/cangodmakearock">could not</a> <a href="http://www.askmoses.com/qa_detail.html?h=419&o=237">lift it?</a>

The spaceless tag would remove the spaces between these links entirely, causing them to look like this:

CanGodmakearocksoheavythathecouldnotliftit?

The solution is to replace multiple whitespace with a single space rather than removing them entirely. A more complex solution would be to remove ALL whitespace between block-level tags but leave space beteween inline tags, but the complexity and performance overhead of doing this probably prohibits it.

Change History (3)

comment:1 Changed 10 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(In [1969]) Fixed #1227 -- Fixed problem with new {% spaceless %} tag. It now normalizes spaces to a single space rather than no spaces

comment:2 Changed 6 years ago by cfinke

  • Resolution fixed deleted
  • Status changed from closed to reopened

This bug has since been re-introduced.

The latest code shows that the function is back to :

return re.sub(r'>\s+<', '><', force_unicode(value))

instead of

return re.sub(r'>\s+<', '> <', force_unicode(value))

comment:3 Changed 6 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from reopened to closed

This was done intentionally (and after quite a bit of discussion, from memory) in r4885 (see #3532).

Note: See TracTickets for help on using tickets.
Back to Top