Skip to content

Commit

Permalink
Add illegal character check to LogicProcessor to detect common substi…
Browse files Browse the repository at this point in the history
…tution errors.
  • Loading branch information
homothetyhk committed Apr 16, 2023
1 parent cbb84cb commit d6a629c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions RandomizerCore/StringLogic/LogicProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public ComparisonToken GetComparisonToken(ComparisonType comparisonType, string
}
}

private static readonly HashSet<char> illegalSimpleTokenChars = new() { '|', '+', '<', '>', '=', '?', '(', ')', '*' };

public TermToken GetTermToken(string name)
{
if (globalTokens.TryGetValue(name, out LogicToken lt) || tokenPool.TryGetValue(name, out lt)) return (TermToken)lt;
Expand All @@ -134,6 +136,8 @@ public TermToken GetTermToken(string name)
return rt;
}

if (name.Any(illegalSimpleTokenChars.Contains)) throw new ArgumentException($"Failed to convert {name} to token due to illegal characters.");

TermToken tt = new SimpleToken(name);
tokenPool.Add(name, tt);
return tt;
Expand Down

0 comments on commit d6a629c

Please sign in to comment.