nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: pallets/jinja
Pull request #1537 (2021-11-09 16:19:52)

native: keep same behavior on Python 3.10
<!--
Ensure each step in CONTRIBUTING.rst is complete by adding an "x" to each box below.

If only docs were changed, these aren't relevant and can be removed.
-->

Checklist:

- [ ] Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
- [ ] Add or update relevant docs, in the docs folder and in code.
- [ ] Add an entry in `CHANGES.rst` summarizing the change and linking to the issue.
- [ ] Add `.. versionchanged::` entries in any relevant code docs.
- [ ] Run `pre-commit` hooks and fix any issues.
- [ ] Run `pytest` and `tox`, no tests failed.


davidism: Seems appropriate for a bugfix release, can you rebase this to 3.0.x?
mkrizek: > Seems appropriate for a bugfix release, can you rebase this to 3.0.x?

Done.

Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index de9bd455..e859ab3f 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -7,6 +7,8 @@ Unreleased
 
 -   Fix traceback rewriting internals for Python 3.10 and 3.11.
     :issue:`1535`
+-   Fix how the native environment treats leading and trailing spaces
+    when parsing values on Python 3.10. :pr:`1537`
 
 
 Version 3.0.2
diff --git a/src/jinja2/nativetypes.py b/src/jinja2/nativetypes.py
index 88eeecc4..20597d50 100644
--- a/src/jinja2/nativetypes.py
+++ b/src/jinja2/nativetypes.py
@@ -1,5 +1,6 @@
 import typing as t
 from ast import literal_eval
+from ast import parse
 from itertools import chain
 from itertools import islice
 
@@ -33,7 +34,12 @@ def native_concat(values: t.Iterable[t.Any]) -> t.Optional[t.Any]:
         raw = "".join([str(v) for v in chain(head, values)])
 
     try:
-        return literal_eval(raw)
+        return literal_eval(
+            # In Python 3.10+ ast.literal_eval removes leading spaces/tabs
+            # from the given string. For backwards compatibility we need to
+            # parse the string ourselves without removing leading spaces/tabs.
+            parse(raw, mode="eval")
+        )
     except (ValueError, SyntaxError, MemoryError):
         return raw
 


Test patch:
diff --git a/tests/test_nativetypes.py b/tests/test_nativetypes.py
index 22581813..9bae938c 100644
--- a/tests/test_nativetypes.py
+++ b/tests/test_nativetypes.py
@@ -147,3 +147,9 @@ def test_no_intermediate_eval(env):
 def test_spontaneous_env():
     t = NativeTemplate("{{ true }}")
     assert isinstance(t.environment, NativeEnvironment)
+
+
+def test_leading_spaces(env):
+    t = env.from_string(" {{ True }}")
+    result = t.render()
+    assert result == " True"
Repository: pallets/jinja
Pull request #2062 (2024-12-20 04:40:27)

don't apply `urlize` to `@a@b`
Don't apply `urlize` to values like `@a@b`.

continues #1870 


Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 3955a32b..e31de857 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -40,6 +40,7 @@ Unreleased
 -   ``PackageLoader`` shows a clearer error message when the package does not
     contain the templates directory. :issue:`1705`
 -   Improve annotations for methods returning copies. :pr:`1880`
+-   ``urlize`` does not add ``mailto:`` to values like `@a@b`. :pr:`1870`
 
 
 Version 3.1.4
diff --git a/src/jinja2/utils.py b/src/jinja2/utils.py
index d7149bc3..7c922629 100644
--- a/src/jinja2/utils.py
+++ b/src/jinja2/utils.py
@@ -333,6 +333,8 @@ def urlize(
         elif (
             "@" in middle
             and not middle.startswith("www.")
+            # ignore values like `@a@b`
+            and not middle.startswith("@")
             and ":" not in middle
             and _email_re.match(middle)
         ):


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 86e0f042..b50a6b4c 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -142,6 +142,14 @@ class TestEscapeUrlizeTarget:
             "http://example.org</a>"
         )
 
+    def test_urlize_mail_mastodon(self):
+        fr = "nabijaczleweli@nabijaczleweli.xyz\n@eater@cijber.social\n"
+        to = (
+            '<a href="mailto:nabijaczleweli@nabijaczleweli.xyz">'
+            "nabijaczleweli@nabijaczleweli.xyz</a>\n@eater@cijber.social\n"
+        )
+        assert urlize(fr) == to
+
 
 class TestLoremIpsum:
     def test_lorem_ipsum_markup(self):