From 7bd68365ecc5750ddd5e581b6223de7c22984df5 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 26 Oct 2021 14:08:35 +0200 Subject: [PATCH] syntaxes: avoid coloring "this\" as if it were a valid string A backslash should not be allowed inside a quoted string unless it is used to escape another character. This fixes https://savannah.gnu.org/bugs/?61389. Bug existed since each of these syntaxes was introduced. (Awk and Fortran do not know include files with names between angled brackets, so those regexes are dropped in the bargain.) --- syntax/asm.nanorc | 2 +- syntax/awk.nanorc | 2 +- syntax/elisp.nanorc | 2 +- syntax/extra/fortran.nanorc | 2 +- syntax/extra/gentoo.nanorc | 2 +- syntax/extra/haskell.nanorc | 4 ++-- syntax/go.nanorc | 4 ++-- syntax/guile.nanorc | 2 +- syntax/html.nanorc | 2 +- syntax/javascript.nanorc | 2 +- syntax/nftables.nanorc | 2 +- syntax/objc.nanorc | 4 ++-- syntax/php.nanorc | 2 +- syntax/sh.nanorc | 2 +- syntax/tcl.nanorc | 2 +- 15 files changed, 18 insertions(+), 18 deletions(-) diff --git a/syntax/asm.nanorc b/syntax/asm.nanorc index 0d2293d1..4bcae332 100644 --- a/syntax/asm.nanorc +++ b/syntax/asm.nanorc @@ -12,7 +12,7 @@ color brightred "^[[:blank:]]*[.0-9A-Za-z_]*:" color brightcyan "^[[:blank:]]*#[[:blank:]]*(define|undef|include|ifn?def|endif|elif|else|if|warning|error)" # Strings. -color brightyellow "<[^= ]*>" ""(\\.|[^"])*"" +color brightyellow "<[^= ]*>|"(\\.|[^"\])*"" # Comments. color brightblue "//.*" diff --git a/syntax/awk.nanorc b/syntax/awk.nanorc index 5e6c3197..13b92c5f 100644 --- a/syntax/awk.nanorc +++ b/syntax/awk.nanorc @@ -29,7 +29,7 @@ color magenta "\<(and|compl|lshift|or|rshift|xor)\>" color magenta "\<(bindtextdomain|dcgettext|dcngettext)\>" # Strings. -color brightyellow "<[^= ]*>" ""(\\.|[^"])*"" +color brightyellow ""(\\.|[^"\])*"" # Comments. color brightblue "(^|[[:blank:]])#.*" diff --git a/syntax/elisp.nanorc b/syntax/elisp.nanorc index 44b788b6..165ed6cd 100644 --- a/syntax/elisp.nanorc +++ b/syntax/elisp.nanorc @@ -28,6 +28,6 @@ color brightred "\<(t|nil)\>" color blue ":(\w|[?-])+" # Strings color yellow start="^[[:blank:]]+"" end="[^\]"" -color yellow ""(\\.|[^"])*"" +color yellow ""(\\.|[^"\])*"" # Comments color cyan "(^|[[:blank:]]);.*" diff --git a/syntax/extra/fortran.nanorc b/syntax/extra/fortran.nanorc index 7704ab92..87f070d8 100644 --- a/syntax/extra/fortran.nanorc +++ b/syntax/extra/fortran.nanorc @@ -34,7 +34,7 @@ icolor yellow "\<(.or.|repeat|select case|then|where|while)\>" icolor magenta "\<(continue|cycle|exit|go?to|result|return)\>" # Strings. -color yellow "<[^= ]*>" ""(\\.|[^"])*"" +color yellow ""(\\.|[^"\])*"" # Comments. color blue "!.*" diff --git a/syntax/extra/gentoo.nanorc b/syntax/extra/gentoo.nanorc index ea3c21d4..756b12b6 100644 --- a/syntax/extra/gentoo.nanorc +++ b/syntax/extra/gentoo.nanorc @@ -41,7 +41,7 @@ color blue "\<(awk|cat|cd|chmod|chown|cp|echo|env|find|e?grep|ln|make|mkdir|mv|p ## Comments (doesn't work that well): color yellow "(^|[[:space:]])#.*" ## Strings (doesn't work that well): -color brightyellow ""(\\.|[^\"])*"|'(\\.|[^'])*'" +color brightyellow ""(\\.|[^"\])*"|'(\\.|[^'\])*'" ## Trailing space is bad! color ,green "[[:space:]]+$" ## Mixed whitespace is also bad. diff --git a/syntax/extra/haskell.nanorc b/syntax/extra/haskell.nanorc index 7acf35c4..0abc7185 100644 --- a/syntax/extra/haskell.nanorc +++ b/syntax/extra/haskell.nanorc @@ -28,9 +28,9 @@ color magenta "\<(Bounded|Data|Enum|Eq|Floating|Fractional|Functor|Integral|Mona color brightred "undefined" # Strings -color yellow ""([^\"]|\\.)*"" +color yellow ""([^"\]|\\.)*"" # Characters -color brightyellow "'([^\']|\\.)'" +color brightyellow "'([^'\]|\\.)'" # Comments color green "--.*" diff --git a/syntax/go.nanorc b/syntax/go.nanorc index 31dc381d..e6499d43 100644 --- a/syntax/go.nanorc +++ b/syntax/go.nanorc @@ -34,8 +34,8 @@ color red "\<[0-9]+i\>" # Strings and characters; slightly fuzzy. color red "\<(true|false|nil|iota|_)\>" -color red ""(\\.|[^"])*"|'(\\.|[^'])+'" -color red start=""(\\.|[^"])*\\[[:blank:]]*$" end="^(\\.|[^"])*"" +color red ""(\\.|[^"\])*"|'(\\.|[^'\])+'" +color red start=""(\\.|[^"\])*\\[[:blank:]]*$" end="^(\\.|[^"\])*"" # Comments. color brightblue "//.*" diff --git a/syntax/guile.nanorc b/syntax/guile.nanorc index 2f41e330..e75336d5 100644 --- a/syntax/guile.nanorc +++ b/syntax/guile.nanorc @@ -19,6 +19,6 @@ color brightred "(#t|#f)\>" color blue "#?:(\w|[?-])+" # Strings color yellow start="^[[:blank:]]+"" end="[^\]"" -color yellow ""(\\.|[^"])*"" +color yellow ""(\\.|[^"\])*"" # Comments color cyan "(^|[[:blank:]]);.*" diff --git a/syntax/html.nanorc b/syntax/html.nanorc index d34fe5a9..06f461e5 100644 --- a/syntax/html.nanorc +++ b/syntax/html.nanorc @@ -25,7 +25,7 @@ color red "\<(rows(pan)?|rules|scheme|scope|scrolling|selected|shape|size|span|s color red "\<(tabindex|target|text|title|type|usemap|valign|value(type)?|vlink|vspace|width|xmlns|xml:space)=" # Strings: -color green ""(\\.|[^"])*"" +color green ""(\\.|[^"\])*"" # Comments: color yellow start="" diff --git a/syntax/javascript.nanorc b/syntax/javascript.nanorc index 2f8faa30..64161ad9 100644 --- a/syntax/javascript.nanorc +++ b/syntax/javascript.nanorc @@ -17,7 +17,7 @@ color cyan "\<([0-9]+|0x[0-9A-Fa-f]+)\>" color cyan "\<(true|false|null|undefined)\>" # Strings. -color brightmagenta ""(\\.|[^"])*"|'(\\.|[^'])*'|`(\\.|[^`])*`" +color brightmagenta ""(\\.|[^"\])*"|'(\\.|[^'\])*'|`(\\.|[^`\])*`" # Comments. color brightblue "(^|[[:blank:]])//.*" color brightblue start="/\*" end="\*/" diff --git a/syntax/nftables.nanorc b/syntax/nftables.nanorc index b057c7cb..d042af5a 100644 --- a/syntax/nftables.nanorc +++ b/syntax/nftables.nanorc @@ -26,7 +26,7 @@ color cyan "(^|[[:blank:]])#.*" color ,green "[[:space:]]+$" # Strings and others -color yellow ""(\\.|[^"])*"|'(\\.|[^'])*'" +color yellow ""(\\.|[^"\])*"|'(\\.|[^'\])*'" color green "[][{}():;|`$<>!=&\]" # Basic variable names diff --git a/syntax/objc.nanorc b/syntax/objc.nanorc index 65c03b5f..8b452df3 100644 --- a/syntax/objc.nanorc +++ b/syntax/objc.nanorc @@ -25,8 +25,8 @@ color white "\[[^][:blank:]]*\]" # Strings. color brightblack "'([^'\]|(\\["'abfnrtv\]))'" "'\\(([0-3]?[0-7]{1,2}))'" "'\\x[0-9A-Fa-f]{1,2}'" -color brightblack "<[^= ]*>" ""(\\.|[^"])*"" -color brightblue "@"(\\.|[^"])*"" +color brightblack "<[^= ]*>|"(\\.|[^"\])*"" +color brightblue "@"(\\.|[^"\])*"" # Preprocessor commands. color brightblue "^[[:blank:]]*#[[:blank:]]*(define|include|import|(un|ifn?)def|endif|el(if|se)|if|warning|error)" diff --git a/syntax/php.nanorc b/syntax/php.nanorc index ede0760c..43fd3fb9 100644 --- a/syntax/php.nanorc +++ b/syntax/php.nanorc @@ -25,7 +25,7 @@ color brightcyan "\<(and|or|xor)\>" color magenta "\<(break|continue|goto|return)\>" # Strings. -color brightyellow ""(\\.|[^"])*"|'(\\.|[^'])*'" +color brightyellow ""(\\.|[^"\])*"|'(\\.|[^'\])*'" # Comments. color brightblue "(^|[[:blank:]]+)//.*" diff --git a/syntax/sh.nanorc b/syntax/sh.nanorc index aa520c5d..e3c270ec 100644 --- a/syntax/sh.nanorc +++ b/syntax/sh.nanorc @@ -33,7 +33,7 @@ color brightred "\$\{[#!]?([-@*#?$!]|[0-9]+|[[:alpha:]_][[:alnum:]_]*)(\[([[:bla color cyan "(^|[[:blank:]])#.*" # Strings. -color brightyellow ""(\\.|[^"])*"|'(\\.|[^'])*'" +color brightyellow ""(\\.|[^"\])*"|'(\\.|[^'\])*'" # Trailing whitespace. color ,green "[[:space:]]+$" diff --git a/syntax/tcl.nanorc b/syntax/tcl.nanorc index 224a7884..721f9b84 100644 --- a/syntax/tcl.nanorc +++ b/syntax/tcl.nanorc @@ -17,7 +17,7 @@ color green "\<(alarm|auto_load_pkg|bsearch|catclose|catgets|catopen|ccollate|cc # Syntax: color brightblue "\|!|=|&|\|" -color brightyellow ""(\\.|[^"])*"|'(\\.|[^'])*'" +color brightyellow ""(\\.|[^"\])*"|'(\\.|[^'\])*'" color brightred "\$\{?[0-9A-Za-z_!@#$*?-]+\}?" # Trailing whitespace: