diff options
| author | Takahiro Fujiwara <wutali.no@gmail.com> | 2013-02-19 02:20:12 +0900 |
|---|---|---|
| committer | Takahiro Fujiwara <wutali.no@gmail.com> | 2013-02-19 02:20:12 +0900 |
| commit | de6b2875091e0b03e22e2e51ce0db938ecf4b98a (patch) | |
| tree | c60368951234a31450993cf9ca230a4ac075843d | |
| parent | eeadb3a763fe2da39fbdc4c645ac786257b3bd73 (diff) | |
| download | pyramid-de6b2875091e0b03e22e2e51ce0db938ecf4b98a.tar.gz pyramid-de6b2875091e0b03e22e2e51ce0db938ecf4b98a.tar.bz2 pyramid-de6b2875091e0b03e22e2e51ce0db938ecf4b98a.zip | |
Added edged test cases for templating with escpaed doubled braces.
| -rw-r--r-- | pyramid/scaffolds/template.py | 6 | ||||
| -rw-r--r-- | pyramid/tests/test_scaffolds/test_template.py | 12 |
2 files changed, 14 insertions, 4 deletions
diff --git a/pyramid/scaffolds/template.py b/pyramid/scaffolds/template.py index b587adb73..d88f5b2a6 100644 --- a/pyramid/scaffolds/template.py +++ b/pyramid/scaffolds/template.py @@ -149,15 +149,15 @@ def substitute_double_braces(content, values): value = match.group('braced').strip() return values[value] return double_brace_pattern.sub(double_bracerepl, content) - -escaped_double_brace_pattern = re.compile(r'\\{\\{(?P<escape_braced>.*?)\\}\\}') + +escaped_double_brace_pattern = re.compile(r'\\{\\{(?P<escape_braced>[^\\]*?)\\}\\}') def substitute_escaped_double_braces(content): def escaped_double_bracerepl(match): value = match.group('escape_braced').strip() return "{{%(value)s}}" % locals() return escaped_double_brace_pattern.sub(escaped_double_bracerepl, content) - + def _add_except(exc, info): # pragma: no cover if not hasattr(exc, 'args') or exc.args is None: return diff --git a/pyramid/tests/test_scaffolds/test_template.py b/pyramid/tests/test_scaffolds/test_template.py index da6caffb9..2e961c516 100644 --- a/pyramid/tests/test_scaffolds/test_template.py +++ b/pyramid/tests/test_scaffolds/test_template.py @@ -37,11 +37,21 @@ class TestTemplate(unittest.TestCase): result = inst.render_template('{{a}}', {'a':None}) self.assertEqual(result, b'') - def test_render_template_with_escaped_double_quotes(self): + def test_render_template_with_escaped_double_braces(self): inst = self._makeOne() result = inst.render_template('{{a}} {{b}} \{\{a\}\} \{\{c\}\}', {'a':'1', 'b':'2'}) self.assertEqual(result, bytes_('1 2 {{a}} {{c}}')) + def test_render_template_with_breaking_escaped_braces(self): + inst = self._makeOne() + result = inst.render_template('{{a}} {{b}} \{\{a\} \{b\}\}', {'a':'1', 'b':'2'}) + self.assertEqual(result, bytes_('1 2 \{\{a\} \{b\}\}')) + + def test_render_template_with_escaped_single_braces(self): + inst = self._makeOne() + result = inst.render_template('{{a}} {{b}} \{a\} \{b', {'a':'1', 'b':'2'}) + self.assertEqual(result, bytes_('1 2 \{a\} \{b')) + def test_module_dir(self): import sys import pkg_resources |
