@@ -76,6 +76,9 @@ registerScriptlet(editOutboundObjectFn, {
76
76
* Prune properties from an object returned by a specific method.
77
77
* Properties can only be removed.
78
78
*
79
+ * @param propChain
80
+ * Property chain of the method to trap.
81
+ *
79
82
* @param jsonq
80
83
* A uBO-flavored JSONPath query.
81
84
*
@@ -96,10 +99,13 @@ registerScriptlet(editOutboundObject, {
96
99
* @scriptlet trusted-edit-outbound-object.js
97
100
*
98
101
* @description
99
- * Edit properties from an object returned by a specific method.
102
+ * Edit properties of an object returned by a specific method.
100
103
* Properties can be assigned new values.
101
104
*
102
- * @param jsonq
105
+ * @param propChain
106
+ * Property chain of the method to trap.
107
+ *
108
+ * @param jsonq
103
109
* A uBO-flavored JSONPath query.
104
110
*
105
111
* */
@@ -166,6 +172,131 @@ registerScriptlet(trustedJsonEdit, {
166
172
/******************************************************************************/
167
173
/******************************************************************************/
168
174
175
+ function editInboundObjectFn (
176
+ trusted = false ,
177
+ propChain = '' ,
178
+ argPosRaw = '' ,
179
+ jsonq = '' ,
180
+ ) {
181
+ if ( propChain === '' ) { return ; }
182
+ const safe = safeSelf ( ) ;
183
+ const logPrefix = safe . makeLogPrefix (
184
+ `${ trusted ? 'trusted-' : '' } edit-inbound-object` ,
185
+ propChain ,
186
+ jsonq
187
+ ) ;
188
+ const jsonp = JSONPath . create ( jsonq ) ;
189
+ if ( jsonp . valid === false || jsonp . value !== undefined && trusted !== true ) {
190
+ return safe . uboLog ( logPrefix , 'Bad JSONPath query' ) ;
191
+ }
192
+ const argPos = parseInt ( argPosRaw , 10 ) ;
193
+ if ( isNaN ( argPos ) ) { return ; }
194
+ const getArgPos = args => {
195
+ if ( argPos >= 0 ) {
196
+ if ( args . length <= argPos ) { return ; }
197
+ return argPos ;
198
+ }
199
+ if ( args . length < - argPos ) { return ; }
200
+ return args . length + argPos ;
201
+ } ;
202
+ const editObj = obj => {
203
+ let clone ;
204
+ try {
205
+ clone = safe . JSON_parse ( safe . JSON_stringify ( obj ) ) ;
206
+ } catch {
207
+ }
208
+ if ( typeof clone !== 'object' || clone === null ) { return ; }
209
+ if ( jsonp . apply ( clone ) === 0 ) { return ; }
210
+ safe . uboLog ( logPrefix , 'Edited' ) ;
211
+ if ( safe . logLevel > 1 ) {
212
+ safe . uboLog ( logPrefix , `After edit:\n${ safe . JSON_stringify ( clone , null , 2 ) } ` ) ;
213
+ }
214
+ return clone ;
215
+ } ;
216
+ proxyApplyFn ( propChain , function ( context ) {
217
+ const i = getArgPos ( context . args ) ;
218
+ if ( i !== undefined ) {
219
+ const obj = editObj ( context . args [ i ] ) ;
220
+ if ( obj ) {
221
+ context . args [ i ] = obj ;
222
+ }
223
+ }
224
+ return context . reflect ( ) ;
225
+ } ) ;
226
+ }
227
+ registerScriptlet ( editInboundObjectFn , {
228
+ name : 'edit-inbound-object.fn' ,
229
+ dependencies : [
230
+ JSONPath ,
231
+ proxyApplyFn ,
232
+ safeSelf ,
233
+ ] ,
234
+ } ) ;
235
+
236
+ /******************************************************************************/
237
+ /**
238
+ * @scriptlet edit-inbound-object.js
239
+ *
240
+ * @description
241
+ * Prune properties from an object passed as argument to a specific method.
242
+ * Properties can only be removed.
243
+ *
244
+ * @param propChain
245
+ * Property chain of the method to trap.
246
+ *
247
+ * @param argPos
248
+ * 0-based position of the argument. Use negative integer for position relative
249
+ * to the end.
250
+ *
251
+ * @param jsonq
252
+ * A uBO-flavored JSONPath query.
253
+ *
254
+ * */
255
+
256
+ function editInboundObject ( propChain = '' , argPos = '' , jsonq = '' ) {
257
+ editInboundObjectFn ( false , propChain , argPos , jsonq ) ;
258
+ }
259
+ registerScriptlet ( editInboundObject , {
260
+ name : 'edit-inbound-object.js' ,
261
+ dependencies : [
262
+ editInboundObjectFn ,
263
+ ] ,
264
+ } ) ;
265
+
266
+ /******************************************************************************/
267
+ /**
268
+ * @scriptlet trusted-edit-inbound-object.js
269
+ *
270
+ * @description
271
+ * Edit properties of an object passed as argument to a specific method.
272
+ * Properties can be assigned new values.
273
+ *
274
+ * @param propChain
275
+ * Property chain of the method to trap.
276
+ *
277
+ * @param argPos
278
+ * 0-based position of the argument. Use negative integer for position relative
279
+ * to the end.
280
+ *
281
+ * @param jsonq
282
+ * A uBO-flavored JSONPath query.
283
+ *
284
+ * */
285
+
286
+ function trustedEditInboundObject ( propChain = '' , argPos = '' , jsonq = '' ) {
287
+ editInboundObjectFn ( true , propChain , argPos , jsonq ) ;
288
+ }
289
+ registerScriptlet ( trustedEditInboundObject , {
290
+ name : 'trusted-edit-inbound-object.js' ,
291
+ requiresTrust : true ,
292
+ dependencies : [
293
+ editInboundObjectFn ,
294
+ ] ,
295
+ } ) ;
296
+
297
+ /******************************************************************************/
298
+ /******************************************************************************/
299
+
169
300
function jsonEditXhrResponseFn ( trusted , jsonq = '' ) {
170
301
const safe = safeSelf ( ) ;
171
302
const logPrefix = safe . makeLogPrefix (
0 commit comments