Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: cms/converters.py

Issue 29332956: Issue 3402 - Properly handle nested inline tags (Closed)
Patch Set: Created Dec. 22, 2015, 1:51 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cms/converters.py
diff --git a/cms/converters.py b/cms/converters.py
index 1ab7ec3efcbc13c59c2efe6f4c8d67b280d61edb..2fe2b137fd9ee5b46b39765cc56dc714714b8de2 100644
--- a/cms/converters.py
+++ b/cms/converters.py
@@ -181,11 +181,16 @@ class Converter:
)
for tag in self.whitelist:
+ allowed_tags = [t % re.escape(tag_name)
+ for t in ("\<%s[^<>]*?\>", "\<\/%s\>")
Sebastian Noack 2016/01/21 13:55:56 Nit: None of your escaping applies to regexp as yo
kzar 2016/02/19 14:32:28 Done.
+ for tag_name in self.whitelist.difference({tag})]
Sebastian Noack 2016/01/21 13:55:56 Nit: self.whitelist - {tag} Besides being more co
kzar 2016/02/19 14:32:28 Done.
+ allowed_contents = "(?:%s)" % "|".join(["[^<>]"] + allowed_tags)
saved = saved_attributes.get(tag, [])
for attrs in saved:
attrs = map(stringify_attribute, attrs)
result = re.sub(
- r"%s([^<>]*?)%s" % (re_escape("<%s>" % tag), re_escape("</%s>" % tag)),
+ r"%s(%s*?)%s" % (re_escape("<%s>" % tag), allowed_contents,
Sebastian Noack 2016/01/21 13:55:56 I wonder whether you should parse the content recu
kzar 2016/02/19 14:32:28 I guess so but probably overkill, we didn't check
+ re_escape("</%s>" % tag)),
lambda match: r'<%s%s>%s</%s>' % (
tag,
" " + " ".join(attrs) if attrs else "",
@@ -195,7 +200,8 @@ class Converter:
result, 1, flags=re.S
)
result = re.sub(
- r"%s([^<>]*?)%s" % (re_escape("<%s>" % tag), re_escape("</%s>" % tag)),
+ r"%s(%s*?)%s" % (re_escape("<%s>" % tag), allowed_contents,
+ re_escape("</%s>" % tag)),
r"<%s>\1</%s>" % (tag, tag),
result, flags=re.S
)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld