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

VCommentDict: duplicate keys in rare cases in keys() and as_dict() #45

Closed
lazka opened this issue Jul 4, 2014 · 2 comments
Closed

VCommentDict: duplicate keys in rare cases in keys() and as_dict() #45

lazka opened this issue Jul 4, 2014 · 2 comments
Labels

Comments

@lazka
Copy link
Member

@lazka lazka commented Jul 4, 2014

Originally reported by: Christoph Reiter (Bitbucket: lazka, GitHub: lazka)


From nanik...@gmail.com on December 22, 2009 13:20:04

VCommentDict: duplicate keys in rare cases in keys() and as_dict()

This only happens when identical differently cased keys are present.

Most of the time, this is not a problem, because keys are usually
normalized to lowercase before any operation.

But it is possible to sneak in differently cased keys by using list
methods like append (possibly insert and extend) where no normalization
takes place.
It is also possible, though unlikely, that a file might contain
differently cased keys, in which case it would also be preserved.

VCommentDict methods keys(self) and as_dict(self) seem to be having 
trouble with such cases.

keys(self):
  First set() is called on all keys to weed out any duplicates.
  Afterwards str.lower() is preformed on every member in the key set.
  This is OK for removing duplicate keys with identical casing, 
  but set() should probably be called after str.lower().

  At this point, if there are three keys ("key", "KEY", "Key"),
  the keys method returns ["key", "key", "key"],
  I assume the intended behavior should be a return value of ["key"]

as_dict(self):
  No lowercase normalization is preformed.
  This might be the intended behavior, but an implementation that
  Does not differentiate between case, passes all other tests,
  so i assume this is not the case.

  At this point, if there are three keys ("key", "KEY", "Key"),
  the as_dict method returns a dictionary which contains the very same
  three keys. The attached patch changes it so that it only returns a
  dictionary containing "key".

A diff with simple fixes and a simple test attached.

Attachment: VCommentDict_dup_keys_fix_and_test.diff

Original issue: http://code.google.com/p/mutagen/issues/detail?id=45


@lazka

This comment has been minimized.

Copy link
Member Author

@lazka lazka commented Jul 4, 2014

Original comment by Christoph Reiter (Bitbucket: lazka, GitHub: lazka):


From joe.wreschnig@gmail.com on January 08, 2010 15:16:09

Status: Accepted

@lazka

This comment has been minimized.

Copy link
Member Author

@lazka lazka commented Jul 4, 2014

Original comment by Christoph Reiter (Bitbucket: lazka, GitHub: lazka):


From joe.wreschnig@gmail.com on January 08, 2010 15:28:59

This issue was closed by revision r74 .

Status: Fixed
Mergedinto: -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.