Don't crash when writing a ! end token into the anchor editor

This commit is contained in:
Benjamin Popp 2021-05-02 21:43:47 -05:00
parent 01d401193d
commit 3ed6d9f9c7
2 changed files with 8 additions and 0 deletions

View File

@ -70,6 +70,7 @@ namespace HavenSoft.HexManiac.Core.Models.Runs {
return new FixedLengthStreamStrategy(number);
}
if (endToken.StartsWith("!") && endToken.Length % 2 == 1 && endToken.Substring(1).All(ViewModels.ViewPort.AllHexCharacters.Contains)) {
if (endToken.Length == 1) return null; // end token must be at least 1 byte long
return new EndCodeStreamStrategy(model, endToken.Substring(1).ToUpper());
}
var tokens = endToken.Split("/");

View File

@ -746,6 +746,13 @@ namespace HavenSoft.HexManiac.Tests {
Assert.Equal("bob|=4+a", segment.SerializeFormat);
}
[Fact]
public void CreateTable_BadEndTokenFormat_NoCrash() {
ViewPort.Edit("^table[a:]1 ");
ViewPort.AnchorText = "^table[a:]!";
Assert.Single(Errors);
}
private void ArrangeTrainerPokemonTeamData(byte structType, byte pokemonCount, int trainerCount) {
CreateTextTable(HardcodeTablesModel.PokemonNameTable, 0x180, "ABCDEFGHIJKLMNOP".Select(c => c.ToString()).ToArray());
CreateTextTable(HardcodeTablesModel.MoveNamesTable, 0x1B0, "qrstuvwxyz".Select(c => c.ToString()).ToArray());