Skip to content

Type 'ParseErrorToken' is not a subtype of type 'StartTagToken' in type cast #2035

@ditman

Description

@ditman

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">

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions