juliangut / slim-exception

Slim HTTP exceptions and exception handling

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Special characters in message break XML/JSON representation

ilovemistakes opened this issue · comments

Special characters (double quotes, backslashes, etc.) are not escaped when Json or Xml formatter formats the message:

        return \sprintf(       
            '{"error":{"id":"%s","message":"%s"}}',
            $exception->getIdentifier(),    
            $exception->getMessage()        
        );

So something like new Exception('Double "quotes" here') produces unparsable json:
{"error":{"id":"qK7Mm88nSznmGu5kawSEtT","message":"Double "quotes" here"}}
Straightforward fix is to use json_encode() and htmlspecialchars() in json and xml formatters respectively.

Thanks for the issue, I've push a commit to fix it