rtcarlson
rtcarlson

Reputation: 424

What kinds of things can cause ngSanitize to throw a Parse Error

I have an AngularJS app that parses HTML which largely comes from emails. In some cases data-bind-html will throw a Parse Error but not all cases. I've been unable to determine why.

Does anyone know some types of tokens or syntax that can cause the error?

Here's a sample of a file which trips it up:

,

I received the following error message...:

------------------------------------------------------------------------ The server encountered an unexpected condition that prevented it from

fulfilling the request.

HTTP_Status = 500 (Internal Server Error)

URL =

----------------------------------------- Request Headers ----------------------------------------- POST /ss/servlet/FooServlet/ HTTP/1.1 Accept: Accept: / Host: mydomain.org Content-Length: 141 User-Agent: FooBar/2.1.94 Pragma: no-cache Cache-Control: no-cache Content-Type: application/x-www-form-urlencoded; charset="utf-8" Connection: Keep-Alive Cookie: BIGipServerpool_cookie_apps_ss_8188=rd860o00000000000000000000ffff0a0ad0aco8188; JSESSIONID=5215F941A173B6127E9A95B3E99E3A74

----------------------------------------- Response Headers ----------------------------------------- HTTP/1.1 500 Internal Server Error Server: Apache-Coyote/1.1 Set-Cookie: JSESSIONID=A9B7C98E5359D961DC8958F87CCCF49E; Path=/ss Content-Disposition: attachment; filename="spreadsheet.csv" Content-Description: spreadsheet.csv Content-Transfer-Encoding: binary Content-Type: application/csv;charset=ISO-8859-1 Transfer-Encoding: chunked Date: Wed, 06 Mar 2013 18:46:19 GMT Connection: close

-------------...

Upvotes: 0

Views: 437

Answers (1)

es128
es128

Reputation: 1047

Emails can contain a lot of arbitrary encoding and invalid HTML, such as <[email protected]>. To eliminate the Parse Errors I've implemented my own filter which takes effect before it goes through ngSanitize/bind-html.

ng-bind-html="obj.emailContent | sanitizeEmail"

myModule.filter('sanitizeEmail', function() {
  return function(input) {
    return input.replace(/<[\w-]*\.[\w-]*>/g, '').replace(/<[\w\.\$-]+[\:@].*>/g, '');
  };
});

Upvotes: 0

Related Questions