From 18c51f1ab9088111b734f5bfca2994fa9d4c2dbe Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Sat, 6 Feb 2021 17:00:05 +0000 Subject: [PATCH] Preliminary support for ZIM archives with no namespace (#698) Partially implements #684. --- service-worker.js | 2 +- www/js/app.js | 45 +++++++++++++++++++++++++--------------- www/js/lib/uiUtil.js | 6 +++--- www/js/lib/zimArchive.js | 34 ++++++++++++++++++++++++++---- www/js/lib/zimfile.js | 3 +++ 5 files changed, 65 insertions(+), 25 deletions(-) diff --git a/service-worker.js b/service-worker.js index fa39e2b8e..0b19654ec 100644 --- a/service-worker.js +++ b/service-worker.js @@ -57,7 +57,7 @@ var regexpExcludedURLSchema = /^(?:chrome-extension|example-extension):/i; * In our case, there is also the ZIM file name used as a prefix in the URL * @type {RegExp} */ -var regexpZIMUrlWithNamespace = /(?:^|\/)([^\/]+\/)([-ABIJMUVWX])\/(.+)/; +var regexpZIMUrlWithNamespace = /(?:^|\/)([^/]+\/)([-ABCIJMUVWX])\/(.+)/; self.addEventListener('install', function (event) { event.waitUntil(self.skipWaiting()); diff --git a/www/js/app.js b/www/js/app.js index 5bedd292c..cafeb9cc2 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -1217,14 +1217,14 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys // Compile some regular expressions needed to modify links // Pattern to find a ZIM URL (with its namespace) - see https://wiki.openzim.org/wiki/ZIM_file_format#Namespaces - var regexpZIMUrlWithNamespace = /^[./]*([-ABIJMUVWX]\/.+)$/; - // Regex below finds images, scripts, stylesheets and tracks with ZIM-type metadata and image namespaces [kiwix-js #378] - // It first searches for ]*?\s)(?:src|href)(\s*=\s*["'])(?:\.\.\/|\/)+(?=[-IJ]\/)/ig; + var regexpZIMUrlWithNamespace = /^[./]*([-ABCIJMUVWX]\/.+)$/; + // Regex below finds images, scripts, stylesheets and tracks with ZIM-type metadata and image namespaces [kiwix-js #378]. + // It first searches for ]*?\s)(?:src|href)(\s*=\s*(["']))(?!http)(.+?)(?=\3|\?|#)/ig; // Regex below tests the html of an article for active content [kiwix-js #466] // It inspects every