Adjust cookie parse fix to make it more tolerant.

- Made the algorithm more tolerant of malformed cookies
- Added a test to cover the fix (which currently does pass).