]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-138775: fix handle `python -m base64` stdin correct with EOF signal (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 12 Nov 2025 00:12:57 +0000 (01:12 +0100)
committerGitHub <noreply@github.com>
Wed, 12 Nov 2025 00:12:57 +0000 (00:12 +0000)
gh-138775: fix handle `python -m base64` stdin correct with EOF signal (GH-138776)

* fix: handle  stdin correct with EOF single.
* fix: flollow the comments when pipe stdin use buffer
* Apply suggestions from code review
* fix: apply review comments in Lib/base64.py
* fix: address comments
* Reword comment and NEWS entry.

---------
(cherry picked from commit f5c2a41f9a6b3be95c5be9dbae0a4a3342d356dc)

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
Co-authored-by: yihong <zouzou0208@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Lib/base64.py
Misc/NEWS.d/next/Library/2025-09-11-15-03-37.gh-issue-138775.w7rnSx.rst [new file with mode: 0644]

index cfc57626c40ba915dac440727e19ca1717c3ae2d..f95132a42740517665dd4a75678aa3a29191165a 100644 (file)
@@ -604,7 +604,14 @@ def main():
         with open(args[0], 'rb') as f:
             func(f, sys.stdout.buffer)
     else:
-        func(sys.stdin.buffer, sys.stdout.buffer)
+        if sys.stdin.isatty():
+            # gh-138775: read terminal input data all at once to detect EOF
+            import io
+            data = sys.stdin.buffer.read()
+            buffer = io.BytesIO(data)
+        else:
+            buffer = sys.stdin.buffer
+        func(buffer, sys.stdout.buffer)
 
 
 if __name__ == '__main__':
diff --git a/Misc/NEWS.d/next/Library/2025-09-11-15-03-37.gh-issue-138775.w7rnSx.rst b/Misc/NEWS.d/next/Library/2025-09-11-15-03-37.gh-issue-138775.w7rnSx.rst
new file mode 100644 (file)
index 0000000..455c1a9
--- /dev/null
@@ -0,0 +1,2 @@
+Use of ``python -m`` with :mod:`base64` has been fixed to detect input from a
+terminal so that it properly notices EOF.