Skip to content

Commit

Permalink
Add handling for empty keys
Browse files Browse the repository at this point in the history
  • Loading branch information
R. Tyler Croy committed Nov 5, 2012
1 parent 3e9f08c commit b35f28d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/sting.adb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ package body Sting is
declare
Key : String := Slice (Keys, J);
begin
if Key'Length > Max_Key_Length then
if (Key'Length > Max_Key_Length) or (Key'Length = 0) then
raise Invalid_Key_Error;
end if;

Expand Down
13 changes: 13 additions & 0 deletions test/cases/sting-tests-protocol.adb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ package body Sting.Tests.Protocol is
end Test_Read_Big_Key;


procedure Test_Read_Empty_Key (T : in out Test_Case'Class) is
Cmd : Command;
Buf : constant String := "read /";
begin
Cmd := Parse (Buf);
Assert (False, "Failed to raise an Invalid_Key_Error");
exception
when Invalid_Key_Error =>
null;
end Test_Read_Empty_Key;


--
-- AUnit set up code

Expand All @@ -92,6 +104,7 @@ package body Sting.Tests.Protocol is
Register_Routine (T, Test_Read'Access, "Parse a read command");
Register_Routine (T, Test_Read_Many_Keys'Access, "Parse a read command with composite keys");
Register_Routine (T, Test_Read_Big_Key'Access, "Raise an error when reading a key that's too damn big");
Register_Routine (T, Test_Read_Empty_Key'Access, "Raise an error when reading an empty key");

end Register_Tests;

Expand Down

0 comments on commit b35f28d

Please sign in to comment.