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

Change subject: link: Validate title length in UTF-8 bytes
......................................................................

link: Validate title length in UTF-8 bytes

Reject titles whose UTF-8 encoding exceeds 255 bytes instead of
counting Unicode characters. This catches overlong non-ASCII titles
during parsing, before an API request.

Change-Id: Ie5b8f1a0303f883c38300e4522e370ee74808a3f
---
M pywikibot/page/_links.py
M tests/link_tests.py
2 files changed, 4 insertions(+), 3 deletions(-)

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




diff --git a/pywikibot/page/_links.py b/pywikibot/page/_links.py
index 1999933..7168c79 100644
--- a/pywikibot/page/_links.py
+++ b/pywikibot/page/_links.py
@@ -465,7 +465,7 @@
         if '~~~' in t:
             raise InvalidTitleError(f"(contains ~~~): '{self._text}'")

-        if self._namespace != -1 and len(t) > 255:
+        if self._namespace != -1 and len(t.encode('utf-8')) > 255:
             raise InvalidTitleError(f"(over 255 bytes): '{t}'")

         # "empty" local links can only be self-links
diff --git a/tests/link_tests.py b/tests/link_tests.py
index 9ea19a8..6fb5173 100755
--- a/tests/link_tests.py
+++ b/tests/link_tests.py
@@ -88,7 +88,8 @@
     def test_valid(self) -> None:
         """Test that valid titles are correctly normalized."""
         title_tests = ['Sandbox', 'A "B"', "A 'B'", '.com', '~', '"', "'",
-                       'Foo/.../Sandbox', 'Sandbox/...', 'A~~', 'X' * 252]
+                       'Foo/.../Sandbox', 'Sandbox/...', 'A~~', 'X' * 252,
+                       'Я' * 127 + 'A']

         extended_title_tests = [
             ('Talk:Sandbox', 'Sandbox'),
@@ -174,7 +175,7 @@
             (['A ~~~ Name', 'A ~~~~ Signature', 'A ~~~~~ Timestamp'],
              generate_contains_tilde_exc_regex),

-            ([('x' * 256), ('Invalid:' + 'X' * 248)],
+            ([('x' * 256), ('Invalid:' + 'X' * 248), ('Я' * 128)],
              generate_overlength_exc_regex),

             (['Talk:'],

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1354002?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: Ie5b8f1a0303f883c38300e4522e370ee74808a3f
Gerrit-Change-Number: 1354002
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