do proper escaping before replacing

Change-Id: I9d11038779494a3bb14107369b54c06baead96a9
Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>