Skip to content

Commit 7f27c60

Browse files
committed
Limit variable names to letters, numbers and underscores.
The parser used to allow any non-whitespace character, which could cause problems in practice. For example, you could create a variable with } or = in the name, or a character we may want to use in a syntax extension later.
1 parent 9677b1f commit 7f27c60

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/ruleparser.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,17 @@ void Rules::load(const QString &filename)
8888
// initialize the regexps we will use
8989
QRegExp repoLine("create repository\\s+(\\S+)", Qt::CaseInsensitive);
9090

91+
QString varRegex("[A-Za-z0-9_]+");
92+
9193
QRegExp matchLine("match\\s+(.*)", Qt::CaseInsensitive);
9294
QRegExp matchActionLine("action\\s+(\\w+)", Qt::CaseInsensitive);
9395
QRegExp matchRepoLine("repository\\s+(\\S+)", Qt::CaseInsensitive);
9496
QRegExp matchBranchLine("branch\\s+(\\S+)", Qt::CaseInsensitive);
9597
QRegExp matchRevLine("(min|max) revision (\\d+)", Qt::CaseInsensitive);
9698
QRegExp matchAnnotateLine("annotated\\s+(\\S+)", Qt::CaseInsensitive);
9799
QRegExp matchPrefixLine("prefix\\s+(\\S+)", Qt::CaseInsensitive);
98-
QRegExp declareLine("declare\\s+(\\S+)\\s*=\\s*(\\S+)", Qt::CaseInsensitive);
99-
QRegExp variableLine("\\$\\{(\\S+)\\}", Qt::CaseInsensitive);
100+
QRegExp declareLine("declare\\s+("+varRegex+")\\s*=\\s*(\\S+)", Qt::CaseInsensitive);
101+
QRegExp variableLine("\\$\\{("+varRegex+")\\}", Qt::CaseInsensitive);
100102
QRegExp includeLine("include\\s+(.*)", Qt::CaseInsensitive);
101103

102104
enum { ReadingNone, ReadingRepository, ReadingMatch } state = ReadingNone;

0 commit comments

Comments
 (0)