mirror of
https://github.com/sasjs/core.git
synced 2026-07-23 15:35:29 +00:00
fix: ensure leading blanks are always imported
This commit is contained in:
+2
-1
@@ -331,7 +331,8 @@
|
|||||||
prxchange('s/\\/\\\\/',-1,&&name&i)
|
prxchange('s/\\/\\\\/',-1,&&name&i)
|
||||||
)))))))))))))!!'"';
|
)))))))))))))!!'"';
|
||||||
end;
|
end;
|
||||||
else &&name&i=quote(cats(&&name&i));
|
/* trim (not cats) so leading blanks are retained */
|
||||||
|
else &&name&i='"'!!trim(&&name&i)!!'"';
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
run;
|
run;
|
||||||
|
|||||||
+4
-1
@@ -77,7 +77,10 @@
|
|||||||
data _null_;
|
data _null_;
|
||||||
infile &&_webin_fileref&i termstr=crlf;
|
infile &&_webin_fileref&i termstr=crlf;
|
||||||
input;
|
input;
|
||||||
call symputx('input_statement',_infile_);
|
/* a plain $ informat strips leading blanks - use $char instead */
|
||||||
|
call symputx('input_statement'
|
||||||
|
,prxchange('s/:\$(?=[0-9 ])/:\$char/i',-1,_infile_)
|
||||||
|
);
|
||||||
putlog "&&_webin_name&i input statement: " _infile_;
|
putlog "&&_webin_name&i input statement: " _infile_;
|
||||||
stop;
|
stop;
|
||||||
data &&_webin_name&i;
|
data &&_webin_name&i;
|
||||||
|
|||||||
@@ -74,7 +74,10 @@
|
|||||||
data _null_;
|
data _null_;
|
||||||
infile &&_webin_fileref&i termstr=crlf lrecl=32767;
|
infile &&_webin_fileref&i termstr=crlf lrecl=32767;
|
||||||
input;
|
input;
|
||||||
call symputx('input_statement',_infile_);
|
/* a plain $ informat strips leading blanks - use $char instead */
|
||||||
|
call symputx('input_statement'
|
||||||
|
,prxchange('s/:\$(?=[0-9 ])/:\$char/i',-1,_infile_)
|
||||||
|
);
|
||||||
putlog "&&_webin_name&i input statement: " _infile_;
|
putlog "&&_webin_name&i input statement: " _infile_;
|
||||||
stop;
|
stop;
|
||||||
data &&_webin_name&i;
|
data &&_webin_name&i;
|
||||||
|
|||||||
@@ -11,9 +11,20 @@
|
|||||||
filename webref temp;
|
filename webref temp;
|
||||||
|
|
||||||
data demo;
|
data demo;
|
||||||
|
length x $100;
|
||||||
do x='"','0A'x,'0D'x,'09'x,'00'x,'0E'x,'0F'x,'01'x,'02'x,'10'x,'11'x,'\';
|
do x='"','0A'x,'0D'x,'09'x,'00'x,'0E'x,'0F'x,'01'x,'02'x,'10'x,'11'x,'\';
|
||||||
output;
|
output;
|
||||||
end;
|
end;
|
||||||
|
/* embedded quote variants */
|
||||||
|
x='say "hi" there'; output;
|
||||||
|
x='"fully quoted"'; output;
|
||||||
|
x='back\slash'; output;
|
||||||
|
x='quote and back\"slash'; output;
|
||||||
|
/* leading / trailing blank variants */
|
||||||
|
x=' leading blanks'; output;
|
||||||
|
x=' "leading blanks and quotes"'; output;
|
||||||
|
x='trailing blanks '; output;
|
||||||
|
x=' both '; output;
|
||||||
run;
|
run;
|
||||||
%mp_jsonout(OPEN,jref=webref)
|
%mp_jsonout(OPEN,jref=webref)
|
||||||
%mp_jsonout(OBJ,demo,jref=webref)
|
%mp_jsonout(OBJ,demo,jref=webref)
|
||||||
|
|||||||
@@ -32,4 +32,55 @@ run;
|
|||||||
%mp_assert(
|
%mp_assert(
|
||||||
iftrue=(%str(&checkval)=%str(&sysvlong)),
|
iftrue=(%str(&checkval)=%str(&sysvlong)),
|
||||||
desc=Check if the sysvlong value was created
|
desc=Check if the sysvlong value was created
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
Test that ms_webout(FETCH) retains leading blanks in character values
|
||||||
|
(simulates the CSV format generated by the sasjs adapter, ie an input
|
||||||
|
statement in the first row followed by unquoted data)
|
||||||
|
*/
|
||||||
|
%let fref2=%mf_getuniquefileref();
|
||||||
|
data _null_;
|
||||||
|
file &fref2 lrecl=32767 termstr=crlf;
|
||||||
|
put 'col1:$char10. col2:best.';
|
||||||
|
put ' padded,1';
|
||||||
|
run;
|
||||||
|
%global _webin_fileref _webin_name;
|
||||||
|
%let _webin_fileref=&fref2;
|
||||||
|
%let _webin_name=leadblank;
|
||||||
|
%let _webin_file_count=1;
|
||||||
|
%ms_webout(FETCH)
|
||||||
|
|
||||||
|
data _null_;
|
||||||
|
set leadblank;
|
||||||
|
if col1=' padded' then call symputx('checkblank','PASS');
|
||||||
|
else call symputx('checkblank',cats('FAIL:',col1));
|
||||||
|
run;
|
||||||
|
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(&checkblank=PASS),
|
||||||
|
desc=ms_webout FETCH retains leading blanks with $char informat
|
||||||
|
)
|
||||||
|
|
||||||
|
/* same test, but with a plain $ informat (as sent by some clients) */
|
||||||
|
%let fref3=%mf_getuniquefileref();
|
||||||
|
data _null_;
|
||||||
|
file &fref3 lrecl=32767 termstr=crlf;
|
||||||
|
put 'col1:$10. col2:best.';
|
||||||
|
put ' padded,1';
|
||||||
|
run;
|
||||||
|
%let _webin_fileref=&fref3;
|
||||||
|
%let _webin_name=leadblank2;
|
||||||
|
%let _webin_file_count=1;
|
||||||
|
%ms_webout(FETCH)
|
||||||
|
|
||||||
|
data _null_;
|
||||||
|
set leadblank2;
|
||||||
|
if col1=' padded' then call symputx('checkblank2','PASS');
|
||||||
|
else call symputx('checkblank2',cats('FAIL:',col1));
|
||||||
|
run;
|
||||||
|
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(&checkblank2=PASS),
|
||||||
|
desc=ms_webout FETCH retains leading blanks with $ informat
|
||||||
)
|
)
|
||||||
@@ -44,6 +44,7 @@ data work.somedata1 work.somedata2;
|
|||||||
x=1;
|
x=1;
|
||||||
y=' t"w"o';
|
y=' t"w"o';
|
||||||
z=.z;
|
z=.z;
|
||||||
|
y2=' two';
|
||||||
label x='x factor';
|
label x='x factor';
|
||||||
output;
|
output;
|
||||||
run;
|
run;
|
||||||
@@ -58,14 +59,14 @@ run;
|
|||||||
%let test1=FAIL;
|
%let test1=FAIL;
|
||||||
data _null_;
|
data _null_;
|
||||||
set testlib1.somedata1;
|
set testlib1.somedata1;
|
||||||
if x=1 and y=' t"w"o' and z="Z" then call symputx('test1','PASS');
|
if x=1 and y=' t"w"o' and z="Z" and y2=' two' then call symputx('test1','PASS');
|
||||||
putlog (_all_)(=);
|
putlog (_all_)(=);
|
||||||
run;
|
run;
|
||||||
|
|
||||||
%let test2=FAIL;
|
%let test2=FAIL;
|
||||||
data _null_;
|
data _null_;
|
||||||
set testlib1.somedata2;
|
set testlib1.somedata2;
|
||||||
if x=1 and y=' t"w"o' and z="Z" then call symputx('test2','PASS');
|
if x=1 and y=' t"w"o' and z="Z" and y2=' two' then call symputx('test2','PASS');
|
||||||
putlog (_all_)(=);
|
putlog (_all_)(=);
|
||||||
run;
|
run;
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -104,7 +104,10 @@
|
|||||||
data _null_;
|
data _null_;
|
||||||
infile "%sysfunc(pathname(work))/&table..csv" termstr=crlf ;
|
infile "%sysfunc(pathname(work))/&table..csv" termstr=crlf ;
|
||||||
input;
|
input;
|
||||||
if _n_=1 then call symputx('input_statement',_infile_);
|
/* a plain $ informat strips leading blanks - use $char instead */
|
||||||
|
if _n_=1 then call symputx('input_statement'
|
||||||
|
,prxchange('s/:\$(?=[0-9 ])/:\$char/i',-1,_infile_)
|
||||||
|
);
|
||||||
list;
|
list;
|
||||||
data work.&table;
|
data work.&table;
|
||||||
infile "%sysfunc(pathname(work))/&table..csv" firstobs=2 dsd
|
infile "%sysfunc(pathname(work))/&table..csv" firstobs=2 dsd
|
||||||
@@ -124,7 +127,10 @@
|
|||||||
data _null_;
|
data _null_;
|
||||||
infile indata termstr=crlf lrecl=32767;
|
infile indata termstr=crlf lrecl=32767;
|
||||||
input;
|
input;
|
||||||
if _n_=1 then call symputx('input_statement',_infile_);
|
/* a plain $ informat strips leading blanks - use $char instead */
|
||||||
|
if _n_=1 then call symputx('input_statement'
|
||||||
|
,prxchange('s/:\$(?=[0-9 ])/:\$char/i',-1,_infile_)
|
||||||
|
);
|
||||||
%if %str(&_debug) ge 128 %then %do;
|
%if %str(&_debug) ge 128 %then %do;
|
||||||
if _n_<20 then putlog _infile_;
|
if _n_<20 then putlog _infile_;
|
||||||
else stop;
|
else stop;
|
||||||
|
|||||||
Reference in New Issue
Block a user