jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1334095?usp=email )

Change subject: api: Support immutable sequences in encode_url
......................................................................

api: Support immutable sequences in encode_url

Use sorted() instead of list.sort() so encode_url accepts the documented
sequence types without reordering mutable input supplied by callers.

Change-Id: I897dfba380c6afec24bf1390b5d668cf9b2031e5
---
M pywikibot/data/api/_requests.py
M tests/api_tests.py
2 files changed, 12 insertions(+), 2 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/pywikibot/data/api/_requests.py b/pywikibot/data/api/_requests.py
index ddd99a6..e64fbe7 100644
--- a/pywikibot/data/api/_requests.py
+++ b/pywikibot/data/api/_requests.py
@@ -1417,6 +1417,6 @@
 
     # parameters ending on 'token' should go last
     # wpEditToken should go very last
-    query.sort(key=lambda x: x[0].lower().endswith('token')
-               + (x[0] == 'wpEditToken'))
+    query = sorted(query, key=lambda x: x[0].lower().endswith('token')
+                   + (x[0] == 'wpEditToken'))
     return urlencode(query)
diff --git a/tests/api_tests.py b/tests/api_tests.py
index d804e94..3fe7b14 100755
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -860,10 +860,20 @@
         """Test moving 'token' parameters from a list to the end."""
         query = [('action', 'edit'), ('token', 'a'), ('supertoken', 'b'),
                  ('text', 'text')]
+        original_query = query[:]
         expect = 'action=edit&text=text&token=a&supertoken=b'
         result = api.encode_url(query)
         self.assertEqual(result, expect)
         self.assertIsInstance(result, str)
+        self.assertEqual(query, original_query)
+
+    def test_url_encoding_from_tuple(self) -> None:
+        """Test moving 'token' parameters from a tuple to the end."""
+        query = (('action', 'edit'), ('token', 'a'), ('text', 'text'))
+        expect = 'action=edit&text=text&token=a'
+        result = api.encode_url(query)
+        self.assertEqual(result, expect)
+        self.assertIsInstance(result, str)

     def test_url_encoding_from_dict(self) -> None:
         """Test moving 'token' parameters from a dict to the end."""

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1334095?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I897dfba380c6afec24bf1390b5d668cf9b2031e5
Gerrit-Change-Number: 1334095
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to