Skip to content

Commit

Permalink
Merge pull request #140 from VATSIM-UK/319-region-parser-points-check
Browse files Browse the repository at this point in the history
fix(regionparser): handle invalid number of region points
  • Loading branch information
AndyTWF authored Apr 4, 2021
2 parents 7292454 + a724642 commit 88ed002
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Compiler/Parser/RegionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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))
Expand Down
18 changes: 18 additions & 0 deletions tests/CompilerTest/Parser/RegionParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,24 @@ public void TestItAddsMultipleRegionsData()
"White JSY JSY"
}
}, // Incomplete mid-file
new object[]
{
new List<string>
{
"REGIONNAME TestRegion",
"Red BCN BCN ;comment",
"A"
}
}, // Not enough points data
new object[]
{
new List<string>
{
"REGIONNAME TestRegion",
"Red BCN BCN ;comment",
"A B C"
}
} // Too much points data
};

[Theory]
Expand Down

0 comments on commit 88ed002

Please sign in to comment.