diff --git a/lib/download.gi b/lib/download.gi index 1e01b2e..f3bf36c 100644 --- a/lib/download.gi +++ b/lib/download.gi @@ -247,6 +247,9 @@ InstallMethod( Download, function( url, opt ) local timeout, errors, r, res; + # Do not modify the caller's record when filling in the defaults below. + opt:= ShallowCopy( opt ); + # Set the default for 'verifyCert' if necessary. if not IsBound( opt.verifyCert ) and UserPreference( "utils", "DownloadVerifyCertificate" ) = false then diff --git a/tst/download.tst b/tst/download.tst index e52cc6e..5f52849 100644 --- a/tst/download.tst +++ b/tst/download.tst @@ -1,4 +1,4 @@ -#@local meths, i, urls, pair, url, expected, res1, good1, n, file, res2, good2, contents, r, res3, good3, bad, server, baseurl, iometh +#@local meths, i, urls, pair, url, expected, res1, good1, n, file, res2, good2, contents, r, res3, good3, bad, server, baseurl, iometh, opt, oldpref ############################################################################ ## #W download.tst Utils Package Thomas Breuer @@ -139,6 +139,19 @@ gap> res1:= Download( url, rec( maxTime:= 5 ) );; gap> res1.success = true; true +## 'Download' must not modify the given options record. +## The defaults are filled in only when the preferences differ from their +## default values, hence the 'SetUserPreference' call. +gap> oldpref:= UserPreference( "utils", "DownloadMaxTime" );; +gap> SetUserPreference( "utils", "DownloadMaxTime", 30 ); +gap> opt:= rec();; +gap> res1:= Download( Concatenation( baseurl, "/success" ), opt );; +gap> res1.success; +true +gap> RecNames( opt ); +[ ] +gap> SetUserPreference( "utils", "DownloadMaxTime", oldpref ); + ## test errors and redirects gap> res1:= Download( Concatenation( baseurl, "/missing" ) );; gap> res1.success = false;