Skip to content

Commit

Permalink
Remove bracket unbalanced nodes when sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
blowfishpro committed Sep 14, 2017
1 parent 99bc0bf commit e52a646
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ModuleManager/PatchExtractor.cs
Expand Up @@ -23,6 +23,13 @@ public static PatchList SortAndExtractPatches(UrlDir databaseRoot, IEnumerable<s
{
try
{
if (!url.type.IsBracketBalanced())
{
progress.Error(url, "Error - node name does not have balanced brackets (or a space - if so replace with ?):\n" + url.SafeUrl());
url.parent.configs.Remove(url);
continue;
}

Command command = CommandParser.Parse(url.type, out _);;

Match firstMatch = firstRegex.Match(url.type);
Expand Down
24 changes: 24 additions & 0 deletions ModuleManagerTests/PatchExtractorTest.cs
Expand Up @@ -283,6 +283,30 @@ public void TestSortAndExtractPatches__Exception()
AssertUrlCorrect("@NADE", config3, list.firstPatches[0]);
}

[Fact]
public void TestSortAndExtractPatches__NotBracketBalanced()
{
UrlDir.UrlConfig config1 = CreateConfig("@NODE:FOR[mod1]");
UrlDir.UrlConfig config2 = CreateConfig("@NODE:FOR[");
UrlDir.UrlConfig config3 = CreateConfig("NODE:HAS[#foo[]");

string[] modList = { "mod1" };
PatchList list = PatchExtractor.SortAndExtractPatches(root, modList, progress);

Assert.Empty(root.AllConfigs);

progress.Received().Error(config2, "Error - node name does not have balanced brackets (or a space - if so replace with ?):\nabc/def/@NODE:FOR[");
progress.Received().Error(config3, "Error - node name does not have balanced brackets (or a space - if so replace with ?):\nabc/def/NODE:HAS[#foo[]");

Assert.Empty(list.firstPatches);
Assert.Empty(list.legacyPatches);
Assert.Empty(list.finalPatches);
Assert.Empty(list.modPasses["mod1"].beforePatches);
Assert.Equal(1, list.modPasses["mod1"].forPatches.Count);
AssertUrlCorrect("@NODE", config1, list.modPasses["mod1"].forPatches[0]);
Assert.Empty(list.modPasses["mod1"].afterPatches);
}

private UrlDir.UrlConfig CreateConfig(string name)
{
ConfigNode node = new TestConfigNode(name)
Expand Down

0 comments on commit e52a646

Please sign in to comment.