Skip to content
This repository was archived by the owner on Jun 20, 2019. It is now read-only.
This repository was archived by the owner on Jun 20, 2019. It is now read-only.

Highlighted span doesn't account for escaped characters (and off-by-one) #642

Description

@leonsenft

Consider this example from #641, modified to fit the template value on one line. Doing so requires escaping a quote:

@Component(
  selector: 'app',
  template: '{{quote(value, character: "\'")}}',
  //                       ^^^^^^^^^^^^^^
  //                       Named arguments not allowed in angular templates [disallowed_expression]
)
class AppComponent {
  final = "Hello world!";

  String quote(String value, {this.character: '"'}) => '$character$value$character';
}

The highlighted span intended to demonstrate the source of the warning is both off by one (not sure why), and 1 character too short. It appears as though the length of the highlighted span is calculated from the escaped text, rather than the raw source text. You can verify this by adding more escaped characters:

'{{quote(value, character: "\'\uFFFF")'
                ^^^^^^^^^^^^^^^

Note the span is 6 characters too short (which is the difference between the length of the escaped value, and its raw source). Interestingly, the presence of more than one escaped character fixes the off-by-one error of the span.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions