fix issue caused by malformed JSON in cookie and add test case