@sasjs/core 7.1.7 → 7.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -60,12 +60,15 @@
60
60
  outfile=0
61
61
  )/*/STORE SOURCE*/;
62
62
 
63
- %local inref dttm ds1;
63
+ %local inref dttm ds1 replen;
64
64
  %let inref=%mf_getuniquefileref();
65
65
  %let outref=%mf_getuniquefileref();
66
66
  %if &outfile=0 %then %let outfile=&infile;
67
67
  %let ds1=%mf_getuniquename(prefix=allchars);
68
68
  %let ds2=%mf_getuniquename(prefix=startmark);
69
+ /* a blank replacement is a deletion, so the length of the replacement is read
70
+ * once and the characters are simply dropped when it is empty */
71
+ %let replen=%length(%superq(&replacevar));
69
72
 
70
73
  /* START */
71
74
  %let dttm=%sysfunc(datetime());
@@ -136,12 +139,18 @@ run;
136
139
  filename &outref &outfile recfm=n;
137
140
 
138
141
  data _null_;
139
- length replace $ %length(%superq(&replacevar));
140
- replace=symget("&replacevar");
142
+ %if &replen>0 %then %do;
143
+ length replace $ &replen;
144
+ replace=symget("&replacevar");
145
+ %end;
141
146
  file &outref;
142
147
  do until(eof);
143
148
  set &ds1 end=eof;
144
- if strt ="1" then put replace char.;
149
+ if strt ="1" then do;
150
+ %if &replen>0 %then %do;
151
+ put replace char.;
152
+ %end;
153
+ end;
145
154
  else put sourcechar char1.;
146
155
  end;
147
156
  stop;
package/package.json CHANGED
@@ -54,5 +54,5 @@
54
54
  "devDependencies": {
55
55
  "@nogoo9/gitleaks": "8.30.1-post.2"
56
56
  },
57
- "version": "7.1.7"
57
+ "version": "7.1.8"
58
58
  }
@@ -89,6 +89,7 @@
89
89
  <h4> SAS Macros </h4>
90
90
  @li mp_abort.sas
91
91
  @li mp_binarycopy.sas
92
+ @li mp_replace.sas
92
93
  @li mf_getplatform.sas
93
94
  @li mf_existfileref.sas
94
95
  @li mf_getuniquefileref.sas
@@ -281,7 +282,60 @@ run;
281
282
  %mp_binarycopy(inref=&fname2,outref=&outref)
282
283
  %end;
283
284
  %if &outlib ne 0 %then %do;
284
- libname &outlib JSON fileref=&fname2;
285
+ /* A service run through Viya job execution wraps its response in the
286
+ * transport envelope (>>weboutBEGIN<< ... >>weboutEND<<) - that is what the
287
+ * client frames the response with. The text path in mx_execute strips it,
288
+ * but the JSON engine has no such step and rejects the marker on line one,
289
+ * which is why an aborted child's result looked unparsable when the abort
290
+ * object inside it was perfectly good.
291
+ *
292
+ * Detection is the strip: mp_replace copies a byte at a time, so the markers
293
+ * come out wherever they sit, and a smaller output than input is the answer
294
+ * to "was there an envelope". Probing the first record instead would miss a
295
+ * marker that is not in it, which is the failure this exists to remove,
296
+ * and a result without an envelope keeps the direct libname. */
297
+ %local path2 path3 begvar endvar nil fref3 fref4 fid size2 size4;
298
+ %let fref3=%mf_getuniquefileref();
299
+ %let fref4=%mf_getuniquefileref();
300
+ %let path2=%sysfunc(pathname(&fname2));
301
+ %let path3=%sysfunc(pathname(&fref3));
302
+ %let begvar=%str(>>weboutBEGIN<<);
303
+ %let endvar=%str(>>weboutEND<<);
304
+ %let nil=;
305
+ %mp_replace(infile="&path2",findvar=begvar,replacevar=nil
306
+ ,outfile="&path3")
307
+ %mp_replace(infile="&path3",findvar=endvar,replacevar=nil
308
+ ,outfile="%sysfunc(pathname(&fref4))")
309
+ /* a copy that could not be written is not an outcome: say so, rather than
310
+ * handing the engine an empty file and failing at the libname instead */
311
+ %if %sysfunc(fexist(&fref4)) ne 1 %then %do;
312
+ %mp_abort(mac=&sysmacroname
313
+ ,msg=%str(Unable to strip the result envelope for &uri)
314
+ )
315
+ %end;
316
+ %let fid=%sysfunc(fopen(&fname2));
317
+ %let size2=%sysfunc(finfo(&fid,File Size (bytes)));
318
+ %let fid=%sysfunc(fclose(&fid));
319
+ %let fid=%sysfunc(fopen(&fref4));
320
+ %let size4=%sysfunc(finfo(&fid,File Size (bytes)));
321
+ %let fid=%sysfunc(fclose(&fid));
322
+ %if &size4 < &size2 %then %do;
323
+ /* nothing but envelope is a real outcome - a service that aborted before
324
+ * writing anything - and becomes the empty object the not-found branch
325
+ * hands back, rather than an empty file the engine cannot open */
326
+ %if &size4=0 %then %do;
327
+ data _null_;
328
+ file &fref4;
329
+ put '{}';
330
+ run;
331
+ %end;
332
+ libname &outlib JSON fileref=&fref4;
333
+ %end;
334
+ %else %do;
335
+ libname &outlib JSON fileref=&fname2;
336
+ %end;
337
+ filename &fref3 clear;
338
+ filename &fref4 clear;
285
339
  %end;
286
340
 
287
341
  %if &mdebug=0 %then %do;