Skip to content

Commit

Permalink
PrintFormatted: more thoroughly check arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
wilfwilson authored and ChrisJefferson committed May 11, 2020
1 parent 5c6ad86 commit 9db00cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/string.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ end);

InstallGlobalFunction(PrintFormatted, function(args...)
# Do some very baic argument checking
if not Length(args) > 1 and IsString(args[1]) then
if not (Length(args) > 1 and IsString(args[1])) then
ErrorNoReturn("Usage: PrintFormatted(<string>, <data>...)");
fi;

Expand Down
6 changes: 5 additions & 1 deletion tst/testinstall/format.tst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ gap> StringFormatted("abc{}def",[1,2]) = "abc[ 1, 2 ]def";
true

# Test alternative functions
gap> PrintFormatted();
Error, Usage: PrintFormatted(<string>, <data>...)
gap> PrintFormatted(fail);
Error, Usage: PrintFormatted(<string>, <data>...)
gap> PrintFormatted("abc\n\n");
Error, Usage: PrintFormatted(<string>, <data>...)
gap> PrintFormatted("abc{}\n", 2);
Expand All @@ -72,7 +76,7 @@ gap> PrintToFormatted(OutputTextString(str, false), "abc{}\n", [1,2]);
gap> Print(str);
abc[ 1, 2 ]
gap> PrintFormatted([1,2]);
Error, Usage: StringFormatted(<string>, <data>...)
Error, Usage: PrintFormatted(<string>, <data>...)
gap> PrintToFormatted([1,2]);
Error, Function: number of arguments must be at least 2 (not 1)
gap> PrintToFormatted([1,2], "abc");
Expand Down

0 comments on commit 9db00cd

Please sign in to comment.