When attempting to access attribute values that contain an & (for example, in a src URL), the attributeValueSpans getter throws the following exception:
type 'ParseErrorToken' is not a subtype of type 'StartTagToken' in type cast
package:html/dom.dart 287:37 Node._ensureAttributeSpans
package:html/dom.dart 191:5 Node.attributeValueSpans
test/parser_feature_test.dart 499:21 _testElementSpans.<fn>.<fn>
I wrote a small parser_feature_test that reproduces the issue:
test('attribute values can contain ampersand', () {
final expectedUrl = 'foo?key=value&key2=value2';
final text = '<script src="$expectedUrl">';
final doc = parse(text, generateSpans: true);
final elem = doc.querySelector('script')!;
expect(elem.attributeValueSpans!['src'], isA<FileSpan>()); // Throws
});
The effect is that I can't parse code like:
<script src="foo?key=value&key2=value2">