- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 33.3k
 
gh-110715: Add missing import in zipfile #110822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| 
           Looks good, could you check which versions this needs to be fixed on and add the appropriate backport labels?  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thank you for catching
@JelleZijlstra
Yeah we need to backport this patch to 3.12
| 
           Seems like this code path isn't covered -- should we also add a test? Or would that be impractical?  | 
    
          
 It can be easily added something like this way.     @requires_zlib()
    def test_read_zipfile_warning(self):
        with zipfile.ZipFile(TESTFN, mode='w') as zf:
            # create a file with a non-ASCII name
            filename = '이름.txt'
            filename_encoded = filename.encode('utf-8')
            # create a ZipInfo object with Unicode path extra field
            zip_info = zipfile.ZipInfo(filename)
            tag_for_unicode_path = b'\x75\x70'
            version_of_unicode_path = b'\x01'
            import zlib
            filename_crc = struct.pack('<L', zlib.crc32(filename_encoded))
            extra_data = version_of_unicode_path + filename_crc + b''
            tsize = len(extra_data).to_bytes(2, 'little')
            zip_info.extra = tag_for_unicode_path + tsize + extra_data
            # add the file to the ZIP archive
            zf.writestr(zip_info, b'Hello World!')
        with zipfile.ZipFile(TESTFN, "r") as zf:
            self.assertEqual(zf.filelist[0].filename, "이름.txt") | 
    
| 
           @Eclips4 Would you like to add a test code for this?  | 
    
          
 Yeah, I'll give a try!  | 
    
          
 Done.  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
(cherry picked from commit 4110cfe) Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
| 
           GH-110861 is a backport of this pull request to the 3.12 branch.  | 
    
| 
           Thanks for the review @corona10! 🚀  | 
    
Uh oh!
There was an error while loading. Please reload this page.