dart-archive/angular_analyzer_plugin

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

Opened this issue · 0 comments

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.