faisalman/ua-parser-js — pull request #18 by johnyanarella (2013-08-16 20:40:04+00:00)
Title: Fixed: Unsafe use of for..in loop results in incorrectly parsed values in some JavaScript VMs.

I switched in a traditional `for` loop in place of a `for..in` loop. At first glance, this might just seem like nitpicking; however, this was causing UA-Parser to report incorrect values for us in some JavaScript VMs (for example IE7).

The thing is, `for..in`:

* will enumerate all properties of the Object, not just the indices of the Array
* for example, IE7 executed this loop with `indexOf`, `0`, `1`, and `2` instead of just `0`, `1` and `2`
* consequently, it attempted to populate `indexOf` with the name, `name` was populated with the version, `version` was populated with the major version, and `major` was undefined
* does not guarantee element order
* the logic inside that loop assumes sequential iteration, to keep the properties in sync with the matches

Switching this out for a standard for loop addresses both of these concerns.

The issue described above doesn't show up in the unit tests because of the way node.js / V8 implement `for..in` for Arrays vs. other JavaScript engines.

I executed the `test` target to verify all tests still pass after this change.

Thanks so much for sharing this library - it has proven very useful for my team!