Skip to content
Myr

Merge pull request #1238 from MLH-Fellowship/1197-sandbox

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

Remove sandbox Python < 3.5 compat

authored by David Lord · committed by GitHub · parents 8816c93, 6de6097 · Browse files · 2 files+7 added−32 removed
This commit

State

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

Diff stats

2 files+7 added−32 removed

  • tests:+7 added−0 removed
  • other:+0 added−32 removed

2 files+7 added−32 removed

modified:src/jinja2/sandbox.py-32 removed
73 unmodified lines
74 ),75)767778class _MagicFormatMapping(abc.Mapping):79 """This class implements a dummy wrapper to fix a bug in the Python80 standard library for string formatting.8182 See https://bugs.python.org/issue13598 for information about why83 this is necessary.84 """8586 def __init__(self, args, kwargs):87 self._args = args88 self._kwargs = kwargs89 self._last_index = 09091 def __getitem__(self, key):92 if key == "":93 idx = self._last_index94 self._last_index += 195 try:96 return self._args[idx]97 except LookupError:98 pass99 key = str(idx)100 return self._kwargs[key]101102 def __iter__(self):103 return iter(self._kwargs)104105 def __len__(self):106 return len(self._kwargs)10710878def inspect_format_method(callable):79 if not isinstance(80 callable, (types.MethodType, types.BuiltinMethodType)81 ) or callable.__name__ not in ("format", "format_map"):
281 unmodified lines
363364 kwargs = args[0]365 args = None366398 kwargs = _MagicFormatMapping(args, kwargs)367 rv = formatter.vformat(s, args, kwargs)368 return type(s)(rv)369370 def call(__self, __context, __obj, *args, **kwargs): # noqa: B902
49 unmodified lines
modified:tests/test_security.py+7 added
144 unmodified lines
145 env = SandboxedEnvironment()146 t = env.from_string('{{ ("a{0.foo}b{1}"|safe).format({"foo": 42}, "<foo>") }}')147 assert t.render() == "a42b&lt;foo&gt;"148149 def test_empty_braces_format(self):150 env = SandboxedEnvironment()151 t1 = env.from_string('{{ ("a{}b{}").format("foo", "42")}}')152 t2 = env.from_string('{{ ("a{}b{}"|safe).format(42, "<foo>") }}')153 assert t1.render() == "afoob42"154 assert t2.render() == "a42b&lt;foo&gt;"155156157class TestStringFormatMap:158 def test_basic_format_safety(self):159 env = SandboxedEnvironment()160 t = env.from_string('{{ "a{x.__class__}b".format_map({"x":42}) }}')
13 unmodified lines