Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Source/Data/CodeNote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -661,14 +661,14 @@ private static bool IsValue(Token token)
if (token.StartsWith("0x"))
index += 2;

if (index == token.Length)
if (index == token.Length || !IsHexDigit(token[index]))
return false;

while (IsHexDigit(token[index]))
do
{
if (++index == token.Length)
return true;
}
} while (IsHexDigit(token[index]));

while (index < token.Length && Char.IsWhiteSpace(token[index]))
index++;
Expand All @@ -680,7 +680,7 @@ private static bool IsValue(Token token)
while (index < token.Length && Char.IsWhiteSpace(token[index]))
index++;

if (!IsHexDigit(token[index]))
if (index == token.Length || !IsHexDigit(token[index]))
return false;

do
Expand Down
18 changes: 18 additions & 0 deletions Tests/Data/CodeNoteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,5 +371,23 @@ public void TestPossibleButNotEnum()
Assert.That(n.Size, Is.EqualTo(FieldSize.None));
Assert.That(n.Values.Count(), Is.EqualTo(0));
}

[Test]
public void TestUnboundedRangeEnums()
{
var n = new CodeNote(4, "[8-bit] Chars\n" +
"0-=!\n" + // 0 starts a range, but without an end, it's not valid
"-9=?\n" + // This dash is seen as an indent marker. the mapping "9=?" is processed.
"-=$\n" + // These are all seen as prefix characters and are ignored.
"X=0-" + // 0 starts a range, but without an end, it's not valid
"Y=-9" + // 9 ends a range, but without a start, it's not valid
"Z=-"); // range has neither a start nor an end. it's not valid

Assert.That(n.Summary, Is.EqualTo("Chars"));
Assert.That(n.Size, Is.EqualTo(FieldSize.Byte));
Assert.That(n.Values.Count(), Is.EqualTo(1));
Assert.That(n.Values.First().Key, Is.EqualTo("9"));
Assert.That(n.Values.First().Value, Is.EqualTo("?"));
}
}
}
Loading