From 9db00cdf9c0f083237aede689cdabf5e36c6dc65 Mon Sep 17 00:00:00 2001 From: Wilf Wilson Date: Wed, 29 Apr 2020 22:22:27 +0100 Subject: [PATCH] PrintFormatted: more thoroughly check arguments --- lib/string.gi | 2 +- tst/testinstall/format.tst | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/string.gi b/lib/string.gi index 6df3d33852..2d02a6c489 100644 --- a/lib/string.gi +++ b/lib/string.gi @@ -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(, ...)"); fi; diff --git a/tst/testinstall/format.tst b/tst/testinstall/format.tst index b87f225527..f73df482d0 100644 --- a/tst/testinstall/format.tst +++ b/tst/testinstall/format.tst @@ -62,6 +62,10 @@ gap> StringFormatted("abc{}def",[1,2]) = "abc[ 1, 2 ]def"; true # Test alternative functions +gap> PrintFormatted(); +Error, Usage: PrintFormatted(, ...) +gap> PrintFormatted(fail); +Error, Usage: PrintFormatted(, ...) gap> PrintFormatted("abc\n\n"); Error, Usage: PrintFormatted(, ...) gap> PrintFormatted("abc{}\n", 2); @@ -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(, ...) +Error, Usage: PrintFormatted(, ...) gap> PrintToFormatted([1,2]); Error, Function: number of arguments must be at least 2 (not 1) gap> PrintToFormatted([1,2], "abc");