Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#488 closed defect (fixed)

[patch] removetags filter doesn't remove tags without a seperate ending tag

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

Description

the removetags filter incorrectly doesn't remove <br/> (possibly <img/> as well however I haven't tested).

I've included (sorry I'm unsure of the correct way to create and upload a patch, svn diff includes all my mods to other files) my modified filter which works, someone better with regular expressions can probably tweak the existing ones.

def removetags(value, tags):
    "Removes a space separated list of [X]HTML tags from the output"
    tags = [re.escape(tag) for tag in tags.split()]
    tags_re = '(%s)' % '|'.join(tags)
    starttag_re = re.compile('<%s(>|(\s+[^>]*>))' % tags_re)
    endtag_re = re.compile('</%s>' % tags_re)
    singletag_re = re.compile('<%s*/>' % tags_re)
    value = starttag_re.sub('', value)
    value = endtag_re.sub('', value)
    value = singletag_re.sub('', value)
    return value

Attachments (1)

removetags.patch (599 bytes) - added by ilikeprivacy@… 10 years ago.
patch

Download all attachments as: .zip

Change History (4)

comment:1 Changed 10 years ago by ilikeprivacy@…

  • Component changed from Admin interface to Template system

Changed 10 years ago by ilikeprivacy@…

patch

comment:2 Changed 10 years ago by ilikeprivacy@…

  • Summary changed from removetags filter doesn't remove tags without a seperate ending tag to [patch] removetags filter doesn't remove tags without a seperate ending tag

been a while... still broken :(

comment:3 Changed 10 years ago by adrian

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

(In [1018]) Fixed #488 -- removetags template filter now removes tags without a space before the final slash

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