leosongwei / mutagen

Automatically exported from code.google.com/p/mutagen
GNU General Public License v2.0
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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.

Original issue reported on code.google.com by nanik...@gmail.com on 22 Dec 2009 at 12:20

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by joe.wreschnig@gmail.com on 8 Jan 2010 at 11:16

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r74.

Original comment by joe.wreschnig@gmail.com on 8 Jan 2010 at 11:28