diff --git a/src/Compiler/Parser/RegionParser.cs b/src/Compiler/Parser/RegionParser.cs index 39ad5284..b2582cb5 100644 --- a/src/Compiler/Parser/RegionParser.cs +++ b/src/Compiler/Parser/RegionParser.cs @@ -53,6 +53,7 @@ public void ParseData(AbstractSectorDataFile data) // Expecting a colour definition for the region if (expectingColourDefinition) { + // On lines where we're expecting a colour, we want to see a colour followed by point/latlong if (line.dataSegments.Count != 3) { this.eventLogger.AddEvent( @@ -125,6 +126,15 @@ public void ParseData(AbstractSectorDataFile data) expectingColourDefinition = true; continue; } + + // On lines without colours, we expect to see a point/latlong only + if (line.dataSegments.Count != 2) + { + this.eventLogger.AddEvent( + new SyntaxError("Invalid number of points in REGION" + data.CurrentLine, line) + ); + return; + } Point parsedPoint = PointParser.Parse(line.dataSegments[0], line.dataSegments[1]); if (Equals(parsedPoint, PointParser.InvalidPoint)) diff --git a/tests/CompilerTest/Parser/RegionParserTest.cs b/tests/CompilerTest/Parser/RegionParserTest.cs index 411ac737..3e0cc4ed 100644 --- a/tests/CompilerTest/Parser/RegionParserTest.cs +++ b/tests/CompilerTest/Parser/RegionParserTest.cs @@ -156,6 +156,24 @@ public void TestItAddsMultipleRegionsData() "White JSY JSY" } }, // Incomplete mid-file + new object[] + { + new List + { + "REGIONNAME TestRegion", + "Red BCN BCN ;comment", + "A" + } + }, // Not enough points data + new object[] + { + new List + { + "REGIONNAME TestRegion", + "Red BCN BCN ;comment", + "A B C" + } + } // Too much points data }; [Theory]