Fixes bug with escaping single quotes

Also adds test case. See https://forums.aws.amazon.com/thread.jspa?threadID=100179