Fix escaping of HTML and encoding of URI in Javascript & improve reporting
of errors