browserutils / kooky

Go code to read cookies from browser cookie stores.
MIT License
204 stars 41 forks source link

bugfix: map key set to URL instead of pointer to URL #63

Closed werelord closed 1 year ago

werelord commented 1 year ago

in the following code, the keys to the map were set to be *url.URL (pointers to URL); every iteration of the range loop it would create a new instance of the URL struct with a new pointer associated with it, and use that as the key to the map. In doing so, no two keys (pointers) would be the same even if the underlying URL were the same.

For example, if the cookie slice passed to that method contained 15 cookies all with the same scheme/domain/path, the resulting map would contain 15 keys and 15 arrays of cookies, each array containing one cookie each. This would then cause jar.SetCookies() to be called 15 times.

The simple fix is to use a concrete struct as the map key (one that can be comparable for map keys); with this fix the above example would cause the map to have one entry with an array of 15 cookies, causing jar.SetCookies() to be called only once.

srlehn commented 1 year ago

Thanks a lot for the fix! Using the string representation as key over the struct is probably not worth it. @zellyn LGTM, what do you think?