dart-lang/dart-web-components — pull request #122 by sqs (2012-10-29 02:28:53+00:00)
Title: Failing test of HTML character entity usage in a component

Compiling a component containing certain "exotic" (non-ASCII) HTML character entity references (such as `ƒ`) fails with the following trace:

````
Unhandled exception:
FutureUnhandledException: exception while executing Future
Illegal argument(s):
original stack trace:
#0 _RandomAccessFile.writeString. (dart:io:1491:9)
#1 _FutureImpl.transform. (bootstrap:855:37)
````

When running the test runner on the included character_entity_test.html, this is the (similar) output:

````
$ test/run.sh character_entity_test
~/src/dart-web-components/test ~/src/dart-web-components
unittest-suite-wait-for-done
Parsed character_entity_test.html -- 112 ms
Analyzed definitions character_entity_test.html -- 2 ms
Analyzed contents character_entity_test.html -- 7 ms
Codegen character_entity_test.html -- 35 ms
FAIL: /home/sqs/src/dart-web-components/test/data/input/character_entity_test.html
Expected: true
but: was .
Expected future to complete successfully, but it failed with type 'ArgumentError' is not a subtype of type 'Exception' of 'function result'.
Stack trace:
#0 _FileBase._exceptionFromResponse (dart:io:1032:48)
#1 _RandomAccessFile.writeString. (dart:io:1491:37)
#2 _FutureImpl.transform. (bootstrap:855:37)

#0 DefaultFailureHandler.fail (package:unittest/expect.dart:85:5)
#1 DefaultFailureHandler.failMatch (package:unittest/expect.dart:89:9)
#2 expect (package:unittest/expect.dart:54:29)
#3 _Completes.matches. (package:unittest/future_matchers.dart:44:13)
#4 _SpreadArgsHelper.invoke1.invoke1. (package:unittest/unittest.dart:429:29)
#5 guardAsync (package:unittest/unittest.dart:755:19)

0 PASSED, 1 FAILED, 0 ERRORS
````

The ideal behavior would be for the original document's character entity refs to be preserved after passing the doc through html5lib's .innerHTML, instead of having them interpreted. This might contradict the HTML5 spec, based on a quick reading of http://dev.w3.org/html5/spec-LC/the-end.html#serializing-html-fragments and http://dev.w3.org/html5/spec-LC/infrastructure.html#entity-references. Either way, writeString should be able to handle all Unicode characters.

I don't know the best fix here, but I hope this unit test helps.