Fix off by one in cookie parser

Add tests for cookie parser and fix off by one parsing error.