You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let payload = r#"self.__next_f.push([1,"[\"$\",\"link\",{\"href\":\"/js/prebid.min.js?v=2025-11-20\"}],[\"$\",\"script\",{\"src\":\"/js/prebid.js\",\"children\":\"var pbjs=pbjs||{};pbjs.que=pbjs.que||[];\"}]"]);"#;
281
+
let rewritten = rewrite_nextjs_values(
282
+
payload,
283
+
"origin.example.com",
284
+
"ts.example.com",
285
+
"https",
286
+
&["href".into()],
287
+
true,// remove_prebid enabled
288
+
)
289
+
.expect("should remove prebid file references");
290
+
291
+
assert!(
292
+
!rewritten.contains("prebid.min.js"),
293
+
"Should remove prebid.min.js file references"
294
+
);
295
+
assert!(
296
+
!rewritten.contains("/js/prebid.js"),
297
+
"Should remove prebid.js file references"
298
+
);
299
+
assert!(
300
+
rewritten.contains("pbjs=pbjs||{}"),
301
+
"Should KEEP pbjs initialization (needed by shim)"
302
+
);
303
+
assert!(
304
+
rewritten.contains("pbjs.que"),
305
+
"Should KEEP pbjs.que (needed by shim)"
306
+
);
307
+
assert!(
308
+
rewritten.contains("self.__next_f"),
309
+
"Should preserve Next.js payload structure"
310
+
);
311
+
}
312
+
313
+
#[test]
314
+
fnrewrite_helper_respects_remove_prebid_flag(){
315
+
let payload = r#"self.__next_f.push([1,"var pbjs=pbjs||{};"]);"#;
316
+
317
+
// With remove_prebid = false, should keep prebid code
318
+
let not_removed = rewrite_nextjs_values(
319
+
payload,
320
+
"origin.example.com",
321
+
"ts.example.com",
322
+
"https",
323
+
&["href".into()],
324
+
false,// remove_prebid disabled
325
+
);
326
+
327
+
// Should return None since no attributes to rewrite and prebid removal disabled
let payload = r#"self.__next_f.push([1,"[\"$\",\"script\",{\"src\":\"/js/prebid.min.js\"}],[\"$\",\"script\",{\"children\":\"var pbjs=pbjs||{};\"}]"]);"#;
337
+
let rewriter = NextJsScriptRewriter::new(
338
+
test_config_with_prebid_removal(),
339
+
NextJsRewriteMode::Streamed,
340
+
);
341
+
let result = rewriter.rewrite(payload,&ctx("script"));
342
+
343
+
match result {
344
+
ScriptRewriteAction::Replace(value) => {
345
+
assert!(
346
+
!value.contains("prebid.min.js"),
347
+
"Should remove prebid file references from Next.js payloads"
0 commit comments