From 5d1618e1be12f4e55e94a921fcce0c34bfd9af59 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 6 Nov 2023 07:16:41 -0500 Subject: [PATCH] Reset potential `g` regex before use in `replace=` option Related discussion: https://github.com/uBlockOrigin/uAssets/issues/5184#issuecomment-1794058253 --- src/js/traffic.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/js/traffic.js b/src/js/traffic.js index 34373f30c..493830725 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -602,10 +602,10 @@ const mimeFromHeaders = headers => { const mimeFromContentType = contentType => { const match = reContentTypeMime.exec(contentType); if ( match === null ) { return ''; } - return match[1].toLowerCase(); + return match[0].toLowerCase(); }; -const reContentTypeMime = /^([^;]+)(?:;|$)/i; +const reContentTypeMime = /^[^;]+/i; /******************************************************************************/ @@ -619,7 +619,9 @@ function textResponseFilterer(session, directives) { } const cache = refs.$cache; if ( cache === undefined ) { continue; } + cache.re.lastIndex = 0; if ( cache.re.test(session.getString()) !== true ) { continue; } + cache.re.lastIndex = 0; session.setString(session.getString().replace( cache.re, cache.replacement