Skip to content
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

Inconsistency with uppercase file extensions in MimeTypes.guess_type #64591

Closed
rodrigoparra mannequin opened this issue Jan 25, 2014 · 7 comments
Closed

Inconsistency with uppercase file extensions in MimeTypes.guess_type #64591

rodrigoparra mannequin opened this issue Jan 25, 2014 · 7 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@rodrigoparra
Copy link
Mannequin

rodrigoparra mannequin commented Jan 25, 2014

BPO 20392
Nosy @tjguk, @bitdancer, @asvetlov, @miss-islington, @iritkatriel, @kumaraditya303
PRs
  • bpo-20392: Fix inconsistency with uppercase file extensions in mimetypes.guess_type #30229
  • [3.9] bpo-20392: Fix inconsistency with uppercase file extensions in mimetypes.guess_type (GH-30229) #31903
  • [3.10] bpo-20392: Fix inconsistency with uppercase file extensions in mimetypes.guess_type (GH-30229) #31904
  • Files
  • case_guess_type.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2022-03-15.15:50:53.918>
    created_at = <Date 2014-01-25.17:17:48.028>
    labels = ['easy', 'type-bug', '3.9', '3.10', '3.11', 'library']
    title = 'Inconsistency with uppercase file extensions in MimeTypes.guess_type'
    updated_at = <Date 2022-03-15.15:50:53.917>
    user = 'https://bugs.python.org/rodrigoparra'

    bugs.python.org fields:

    activity = <Date 2022-03-15.15:50:53.917>
    actor = 'asvetlov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-03-15.15:50:53.918>
    closer = 'asvetlov'
    components = ['Library (Lib)']
    creation = <Date 2014-01-25.17:17:48.028>
    creator = 'rodrigo.parra'
    dependencies = []
    files = ['33703']
    hgrepos = []
    issue_num = 20392
    keywords = ['patch', 'easy']
    message_count = 6.0
    messages = ['209218', '209332', '408460', '415243', '415252', '415258']
    nosy_count = 7.0
    nosy_names = ['tim.golden', 'r.david.murray', 'asvetlov', 'rodrigo.parra', 'miss-islington', 'iritkatriel', 'kumaraditya']
    pr_nums = ['30229', '31903', '31904']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue20392'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @rodrigoparra
    Copy link
    Mannequin Author

    rodrigoparra mannequin commented Jan 25, 2014

    The functions looks up for the file extension in three maps: types_map, suffix_map and encodings_map.

    Lookup in types_map is case insensitive (by calling lower() first).
    Lookup in both suffix_map and encodings_map is case sensitive.

    These can lead to some seemingly counterintuitive results, like:

    a)
    guess_type("foo.tar") == ("application/x-tar", None)
    guess_type("foo.TAR") == ("application/x-tar", None)

    b)
    guess_type("foo.tgz") == ("application/x-tar", "gzip")
    guess_type("foo.TGZ") == (None, None)

    c)
    guess_type("foo.tar.gz") == ("application/x-tar", "gzip")
    guess_type("foo.TAR.GZ") == (None, None)

    Lookup should be case insensitive at least for the suffix_map, in which case (b) would be solved. The submitted patch implements this change.

    As for the encodings_map, I am not so sure, in particular because of the tar.Z extension. I found that the compress command expects the uppercase 'Z'. If someone is relying in the results of guess_type to call compress, errors could occur.

    @rodrigoparra rodrigoparra mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 25, 2014
    @bitdancer
    Copy link
    Member

    I'm tagging this for 3.5 instead, since there are backward compatibility concerns and the 3.4 RC will probably be a couple weeks from now.

    @iritkatriel
    Copy link
    Member

    Reproduced on 3.11.

    @iritkatriel iritkatriel added easy 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes labels Dec 13, 2021
    @asvetlov
    Copy link
    Contributor

    New changeset 5dd7ec5 by Kumar Aditya in branch 'main':
    bpo-20392: Fix inconsistency with uppercase file extensions in mimetypes.guess_type (GH-30229)
    5dd7ec5

    @miss-islington
    Copy link
    Contributor

    New changeset 3c4f24f by Miss Islington (bot) in branch '3.10':
    bpo-20392: Fix inconsistency with uppercase file extensions in mimetypes.guess_type (GH-30229)
    3c4f24f

    @miss-islington
    Copy link
    Contributor

    New changeset 32ae9ab by Miss Islington (bot) in branch '3.9':
    bpo-20392: Fix inconsistency with uppercase file extensions in mimetypes.guess_type (GH-30229)
    32ae9ab

    @ifrh
    Copy link

    ifrh commented May 8, 2022

    This implementation cannot find upercase extensions added via mimetype.add_types more information see
    #92455

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants