Dart Language and http_server package: Exception when processing character "&"

119 views Asked by At

I'm having some trouble sending and processing some files with http_server Dart package. The method "processRequest" throws an exception when processing a body. This is the exception: Uncaught Error: HttpException: Unhandled HTTP entity token

I'm calling "processRequest" as follows:

    HttpBodyHandler.processRequest(request, defaultEncoding: Encoding.getByName("ISO-8859-1")).then((body) {
        (...)
    }, onError: _printError);

This exception occurs with both ISO-8859-1 and UTF-8 only when the body contains the character "&". Is there any way to fix this?

1

There are 1 answers

2
sgjesse On BEST ANSWER

This turned out to be a bug in the http_server Dart package. We where trying to decode HTML entity values in the values from multipart/form-post. The parsing of the HTML entities was wrong and caused values with & characters in them to not work.

I have made this fix https://codereview.chromium.org/730203008, which removed the HTML entity parsing for values from multipart/form-post.

The browsers Chrome, Firefox and Safari might use HTML entities (in the form &#xxxxx; for form values in some cases. One case is if the attribute accept-charset="latin1" is set on the HTML form element. However in that case & characters entered in the for is not encoded, so a general decoding is not possible. The fix mentioned above removes the automatic HTML entity decoding.

Not setting accept-charset on the form element will cause UTF-8 to be used if the Content-Type of the HTML page hosting the form is text/html; charset=utf-8. Using all UTF-8 usually causes fewer problems.