mirror of
git://git.sv.gnu.org/nano.git
synced 2025-01-10 03:22:04 +03:00
rcfile: do not allow a regex for name, header, or magic to be empty
If the user really wants to match anything, ".*" should be used. (This also stops nano looking at the rest of the line as soon as an empty regular expression is encountered. This may seem like poorer feedback than before, but... I think that multiple error messages per line are more confusing than helpful.) This fixes https://savannah.gnu.org/bugs/?57942. Bug existed since before version 2.2.0.
This commit is contained in:
parent
4dab491df2
commit
5eb7145939
17
src/rcfile.c
17
src/rcfile.c
@ -557,6 +557,8 @@ char *parse_argument(char *ptr)
|
||||
* null-terminate it, and return a pointer to the succeeding text. */
|
||||
char *parse_next_regex(char *ptr)
|
||||
{
|
||||
char *starting_point = ptr;
|
||||
|
||||
if (*(ptr - 1) != '"') {
|
||||
jot_error(N_("Regex strings must begin and end with a \" character"));
|
||||
return NULL;
|
||||
@ -573,6 +575,11 @@ char *parse_next_regex(char *ptr)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ptr == starting_point) {
|
||||
jot_error(N_("Empty regex string"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Null-terminate the regex and skip until the next non-blank. */
|
||||
*ptr++ = '\0';
|
||||
|
||||
@ -1073,10 +1080,7 @@ void parse_rule(char *ptr, int rex_flags)
|
||||
if (ptr == NULL)
|
||||
return;
|
||||
|
||||
if (*regexstring == '\0') {
|
||||
jot_error(N_("Empty regex string"));
|
||||
goodstart = FALSE;
|
||||
} else {
|
||||
{
|
||||
newcolor = (colortype *)nmalloc(sizeof(colortype));
|
||||
goodstart = compile(regexstring, rex_flags, &newcolor->start);
|
||||
}
|
||||
@ -1114,11 +1118,6 @@ void parse_rule(char *ptr, int rex_flags)
|
||||
if (ptr == NULL)
|
||||
return;
|
||||
|
||||
if (*regexstring == '\0') {
|
||||
jot_error(N_("Empty regex string"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* If the start regex was invalid, the end regex cannot be saved. */
|
||||
if (!goodstart)
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user