trailer: be stricter in parsing separators
Currently, a line is interpreted to be a trailer line if it contains a separator. Make parsing stricter by requiring the text on the left of the separator, if not the empty string, to be of the "<token><optional whitespace>" form. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
be5a750939
commit
e4319562bc
29
trailer.c
29
trailer.c
@ -563,15 +563,32 @@ static int token_matches_item(const char *tok, struct arg_item *item, int tok_le
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the location of the first separator in line, or -1 if there is no
|
* If the given line is of the form
|
||||||
* separator.
|
* "<token><optional whitespace><separator>..." or "<separator>...", return the
|
||||||
|
* location of the separator. Otherwise, return -1. The optional whitespace
|
||||||
|
* is allowed there primarily to allow things like "Bug #43" where <token> is
|
||||||
|
* "Bug" and <separator> is "#".
|
||||||
|
*
|
||||||
|
* The separator-starts-line case (in which this function returns 0) is
|
||||||
|
* distinguished from the non-well-formed-line case (in which this function
|
||||||
|
* returns -1) because some callers of this function need such a distinction.
|
||||||
*/
|
*/
|
||||||
static int find_separator(const char *line, const char *separators)
|
static int find_separator(const char *line, const char *separators)
|
||||||
{
|
{
|
||||||
int loc = strcspn(line, separators);
|
int whitespace_found = 0;
|
||||||
if (!line[loc])
|
const char *c;
|
||||||
return -1;
|
for (c = line; *c; c++) {
|
||||||
return loc;
|
if (strchr(separators, *c))
|
||||||
|
return c - line;
|
||||||
|
if (!whitespace_found && (isalnum(*c) || *c == '-'))
|
||||||
|
continue;
|
||||||
|
if (c != line && (*c == ' ' || *c == '\t')) {
|
||||||
|
whitespace_found = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user