emacsorphanage / dart-mode

An Emacs mode for the Dart language
GNU General Public License v3.0
15 stars 2 forks source link

Non-raw strings with only escape characters aren't handled correctly #104

Closed bradyt closed 5 years ago

bradyt commented 5 years ago

dart-mode fails for an edge case.

In a file with the following,

String a = '\\';
String b = '';

The closing string delimiter on the first line does not terminate the string properly. Also occurs for a string containing only any even number of escape characters.

This is probably a result of the following:

      ;; Look for the end of string delimiter, depending on rawp and
      ;; string-delimiter
      (when (or (looking-at string-delimiter)
                ;; Unless rawp, ensure an even number of backslashes
                (re-search-forward (concat (if rawp "" (rx (not (any ?\\)) (zero-or-more ?\\ ?\\)))
                                           string-delimiter)
                                   end t))

Just as we had to add the looking-at for very short strings like '', we also need to allow for short strings like '\\', that is, the issue is probably the assumed non escape character in (not (any ?\\)).

When we fix this, we should also consider stylistically replacing (if rawp "" with (unless rawp, since concat works fine with a nil argument.

This issue was encountered while reading petitparser_test.dart.

bradyt commented 5 years ago

Presumably fixed by https://github.com/bradyt/dart-mode/commit/d5776f1e9bfeb45eb30723eba3030691a8491545.