Skip to content

Inconsistency with uppercase file extensions in MimeTypes.guess_type #64591

Closed

Description

@rodrigoparra
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']

    Activity

    1. rodrigoparra commented on Jan 25, 2014

      rodrigoparramannequin
      MannequinAuthor

      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.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Jan 25, 2014
    3. bitdancer commented on Jan 26, 2014

      @bitdancer
      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.

    4. iritkatriel commented on Dec 13, 2021

      @iritkatriel
      Member

      Reproduced on 3.11.

    5. asvetlov commented on Mar 15, 2022

      @asvetlov
      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

    6. miss-islington commented on Mar 15, 2022

      @miss-islington
      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

    7. miss-islington commented on Mar 15, 2022

      @miss-islington
      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

    8. transferred this issue fromon Apr 10, 2022
    9. ifrh commented on May 8, 2022

      @ifrh

      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

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of life3.11only security fixes3.9 (EOL)end of lifeeasystdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions