1
0
mirror of https://github.com/sasjs/core.git synced 2025-12-11 06:24:35 +00:00

fix: mp_base64copy.sas fixes, removed renegade % symbol and issue with truncation at character 76. Added two tests, including one to test double byte encoded characters.

This commit is contained in:
Allan Bowe
2021-07-18 17:05:05 +03:00
parent a932f321d8
commit 69f03f4e14
2 changed files with 73 additions and 12 deletions

View File

@@ -76,7 +76,7 @@ run;
%if &outfound=0 %then %do;
filename &outref temp lrecl=2097088;
%%end;
%end;
%if &action=ENCODE %then %do;
data _null_;
@@ -84,12 +84,12 @@ run;
retain line "";
infile &inref recfm=F lrecl= 1 end=eof;
input @1 stream $char1.;
file &outref lrecl=76;
file &outref recfm=N;
substr(line,(_N_-(CEIL(_N_/57)-1)*57),1) = byte(rank(stream));
if mod(_N_,57)=0 or EOF then do;
if eof then b64=put(trim(line),$base64X76.);
else b64=put(line, $base64X76.);
put b64;
put b64 + (-1) @;
line="";
end;
run;
@@ -101,18 +101,12 @@ run;
fileout = fopen("&outref",'O',3,'B');
char= '20'x;
do while(fread(filein)=0);
raw="1234";
length raw $4;
do i=1 to 4;
rc=fget(filein,char,1);
substr(raw,i,1)=char;
end;
val="123";
val=input(raw,$base64X4.);
do i=1 to 3;
length byte $1;
byte=byte(rank(substr(val,i,1)));
rc = fput(fileout, byte);
end;
rc = fput(fileout,input(raw,$base64X4.));
rc = fwrite(fileout);
end;
rc = fclose(filein);

View File

@@ -0,0 +1,67 @@
/**
@file
@brief Testing mp_base64copy.sas macro
<h4> SAS Macros </h4>
@li mp_base64copy.sas
@li mp_assert.sas
**/
/* TEST 1 - regular base64 decode */
%let string1=base ik ally;
filename tmp temp;
data _null_;
file tmp;
put "&string1";
run;
%mp_base64copy(inref=tmp, outref=myref, action=ENCODE)
data _null_;
infile myref;
input;
put _infile_;
run;
%mp_base64copy(inref=myref, outref=mynewref, action=DECODE)
data _null_;
infile mynewref lrecl=5000;
input;
put _infile_;
call symputx('string1_check',_infile_);
stop;
run;
%mp_assert(
iftrue=("&string1"="&string1_check"),
desc=Basic String Compare,
outds=work.test_results
)
/* multibyte string check */
filename tmp2 temp;
data _null_;
file tmp2;
put "'╤', '╔', '╗', '═', '╧', '╚', '╝', '║', '╟', '─', '┼', '║', '╢', '│'";
run;
%mp_base64copy(inref=tmp2, outref=myref2, action=ENCODE)
%mp_base64copy(inref=myref2, outref=newref2, action=DECODE)
data _null_;
infile newref2 lrecl=5000;
input;
list;
/* do not print the string to the log else viya 3.5 throws exception */
if trim(_infile_)=
"'╤', '╔', '╗', '═', '╧', '╚', '╝', '║', '╟', '─', '┼', '║', '╢', '│'"
then call symputx('check2',1);
else call symputx('check2',0);
stop;
run;
%mp_assert(
iftrue=("&check2"="1"),
desc=Double Byte String Compare,
outds=work.test_results
)