Mpaa has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/816295 )

Change subject: [BUGFIX] Exit loop in PageFromFileReader if match.end() <= 0
......................................................................

[BUGFIX] Exit loop in PageFromFileReader if match.end() <= 0

Bug: T313684
Change-Id: I797dbc1f7d12a84740e2ffab2d6b233087e159b2
---
M scripts/pagefromfile.py
1 file changed, 9 insertions(+), 12 deletions(-)

Approvals:
  Mpaa: Looks good to me, approved
  Xqt: Verified



diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py
index a29606f..f1809c2 100755
--- a/scripts/pagefromfile.py
+++ b/scripts/pagefromfile.py
@@ -213,28 +213,25 @@
             pywikibot.error(e)
             return

-        position = 0
         length = 0
-        while True:
+        while text:
             try:
-                length, title, contents = self.findpage(text[position:])
+                length, title, contents = self.findpage(text)
             except AttributeError:
                 if not length:
                     pywikibot.output('\nStart or end marker not found.')
                 else:
                     pywikibot.output('End of file.')
                 break
+
             except NoTitleError as err:
                 pywikibot.output('\nNo title found - skipping a page.')
-                position += err.offset
-                continue
-            if length == 0:
-                break
-            position += length
-
-            page = pywikibot.Page(self.site, title)
-            setattr(page, CTX_ATTR, contents.strip())
-            yield page
+                text = text[err.offset:]
+            else:
+                page = pywikibot.Page(self.site, title)
+                setattr(page, CTX_ATTR, contents.strip())
+                yield page
+                text = text[length:]

     def findpage(self, text) -> Tuple[int, str, str]:
         """Find page to work on."""

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I797dbc1f7d12a84740e2ffab2d6b233087e159b2
Gerrit-Change-Number: 816295
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: JJMC89 <[email protected]>
Gerrit-Reviewer: Mpaa <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to