Skip to content

Commit

Permalink
Fix parse error of system default /usr/share/nano/json.nanorc
Browse files Browse the repository at this point in the history
(Recent) `nano` packages in Ubuntu come with some `.nanorc` files preinstalled.

jline's `NanorcParser` sadly fails parsing `/usr/share/nano/json.nanorc` that comes with Ubuntu's package.

In particular, it fails at this line in `/usr/share/nano/json.nanorc`:
```
color brightblue "[][]"
```
with the exception
```
java.util.regex.PatternSyntaxException: Unclosed character class near index 3
[][]
   ^
...
	at org.jline.builtins.SyntaxHighlighter$NanorcParser.doPattern(SyntaxHighlighter.java:696)
...
```

Fixes jline#1156
  • Loading branch information
snazy committed Jan 20, 2025
1 parent 4504b46 commit 4e472b9
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,11 @@ private void addHighlightRule(String reference, List<String> parts, boolean case
}

private Pattern doPattern(String regex, boolean caseInsensitive) {
if ("[][]".equals(regex)) {
// Some nanorc files, for example json.nanorc, contain this regex that's valid in Nano,
// but not in Java. See https://github.com/jline/jline3/issues/1156
regex = "[\\]\\[]";
}
return caseInsensitive ? Pattern.compile(regex, Pattern.CASE_INSENSITIVE) : Pattern.compile(regex);
}
}
Expand Down

0 comments on commit 4e472b9

Please sign in to comment.