bpo-39055: Reject a trailing \n in base64.b64decode() with validate=True. (GH-17616)

diff --git a/Lib/base64.py b/Lib/base64.py
index 2be9c39..2e70223 100755
--- a/Lib/base64.py
+++ b/Lib/base64.py
@@ -82,7 +82,7 @@
         altchars = _bytes_from_decode_data(altchars)
         assert len(altchars) == 2, repr(altchars)
         s = s.translate(bytes.maketrans(altchars, b'+/'))
-    if validate and not re.match(b'^[A-Za-z0-9+/]*={0,2}$', s):
+    if validate and not re.fullmatch(b'[A-Za-z0-9+/]*={0,2}', s):
         raise binascii.Error('Non-base64 digit found')
     return binascii.a2b_base64(s)
 
diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py
index 2a4cc2a..7dba663 100644
--- a/Lib/test/test_base64.py
+++ b/Lib/test/test_base64.py
@@ -250,6 +250,7 @@
                  (b'3d}==', b'\xdd'),
                  (b'@@', b''),
                  (b'!', b''),
+                 (b"YWJj\n", b"abc"),
                  (b'YWJj\nYWI=', b'abcab'))
         funcs = (
             base64.b64decode,