Skip to content
Myr

Merge pull request #826 from terminalmage/issue823

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix escaped characters in indent filter

authored by David Lord · committed by GitHub · parents 34b1ab9, a2f5e2c · Browse files · 3 files+27 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+27 added−9 removed

  • tests:+17 added−6 removed
  • other:+10 added−3 removed

3 files+27 added−9 removed

modified:jinja2/filters.py+9 added-3 removed
552 unmodified lines
553 'The "indentfirst" argument is renamed to "first".'554 ), stacklevel=2)555 first = indentfirst556557 s += u'\n' # this quirk is necessary for splitlines method557 indention = u' ' * width558 newline = u'\n'559560 if isinstance(s, Markup):561 indention = Markup(indention)562 newline = Markup(newline)563564 s += newline # this quirk is necessary for splitlines method565566 if blank:561 rv = (u'\n' + indention).join(s.splitlines())567 rv = (newline + indention).join(s.splitlines())568 else:569 lines = s.splitlines()570 rv = lines.pop(0)571572 if lines:567 rv += u'\n' + u'\n'.join(573 rv += newline + newline.join(574 indention + line if line else line for line in lines575 )576577 if first:
619 unmodified lines
modified:tests/test_filters.py+17 added-6 removed
133 unmodified lines
134 tmpl = env.from_string('''{{ "%s|%s"|format("a", "b") }}''')135 out = tmpl.render()136 assert out == 'a|b'137138 def test_indent(self, env):139 text = '\n'.join(['', 'foo bar', ''])138 @staticmethod139 def _test_indent_multiline_template(env, markup=False):140 text = '\n'.join(['', 'foo bar', '"baz"', ''])141 if markup:142 text = Markup(text)143 t = env.from_string('{{ foo|indent(2, false, false) }}')141 assert t.render(foo=text) == '\n foo bar\n'144 assert t.render(foo=text) == '\n foo bar\n "baz"\n'145 t = env.from_string('{{ foo|indent(2, false, true) }}')143 assert t.render(foo=text) == '\n foo bar\n '146 assert t.render(foo=text) == '\n foo bar\n "baz"\n '147 t = env.from_string('{{ foo|indent(2, true, false) }}')145 assert t.render(foo=text) == ' \n foo bar\n'148 assert t.render(foo=text) == ' \n foo bar\n "baz"\n'149 t = env.from_string('{{ foo|indent(2, true, true) }}')147 assert t.render(foo=text) == ' \n foo bar\n '150 assert t.render(foo=text) == ' \n foo bar\n "baz"\n '151152 def test_indent(self, env):153 self._test_indent_multiline_template(env)154 t = env.from_string('{{ "jinja"|indent }}')155 assert t.render() == 'jinja'156 t = env.from_string('{{ "jinja"|indent(first=true) }}')157 assert t.render() == ' jinja'158 t = env.from_string('{{ "jinja"|indent(blank=true) }}')159 assert t.render() == 'jinja'160161 def test_indent_markup_input(self, env):162 '''163 Tests cases where the filter input is a Markup type164 '''165 self._test_indent_multiline_template(env, markup=True)166167 def test_indentfirst_deprecated(self, env):168 with pytest.warns(DeprecationWarning):169 env.from_string('{{ "jinja"|indent(indentfirst=true) }}').render()170
493 unmodified lines
modified:.gitignore+1 added
13 unmodified lines
14venv-*/15.coverage16.coverage.*17htmlcov18.pytest_cache/