Fixes #3619 - better parsing and escaping values