From e2ba4a1554a87a43cae8ecdd0dff9eb16fd6af8c Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Sun, 11 Jul 2021 12:46:16 +0100 Subject: [PATCH] Fix bugs with backlinks Former-commit-id: 1ef47c78a3545b017731e91bb2bff422ea8a7a4a [formerly b4c58f8e6c38447facca6db8180e784b42bf7e3e] [formerly 6ef9a48a59d98e9dc45e0950f984b5aaf0b8a57a] [formerly 9a564c9482f32b73b65656ba42760143e483ae21 [formerly 5d69d9fe606df174ad69a8525d939a85289635bc [formerly 7fd26ee7a48ddd067de8692ab5ed1307739d9d46]]] Former-commit-id: e24100ff705940ad32a2741e035364c2ffc35c3a [formerly 690a2cd1b4f81c0c1d919d18cf713adca11b00df [formerly a825d06aa9734559667e9ae615e41d6bfea6b394]] Former-commit-id: ef80ae1c9b638a60d6139eaeda1edb8efee65232 [formerly ecad27caff5673d5eefcd7f4394df1be0cb54e14] Former-commit-id: f44f58462b691f1bf0d7134306fb61dc78dee633 --- CHANGELOG.md | 3 +++ pwabuilder-sw.js | 2 +- www/index.html | 2 ++ www/js/app.js | 15 ++++++++++----- www/js/init.js | 2 +- www/js/lib/zimArchive.js | 2 +- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d2a4e17..87c948a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,12 @@ ## In progress release 1.4.3 * FEATURE: (Experimental) PWA is paritcipating in File Handling API origin trial +* FEATURE: Search with wildcards '.*', '.+' or regex syntax '(?:my_regular_expression)' so long as search begins with normal alphanumeric string * FIX: Bug which failed to detect images correctly in a new tab * FIX: Touch-zoom of contents of iframe no longer blanks part of the display * FIX: Broken zoom of contents of iframe (with UI buttons) in Internet Explorer +* FIX: Bug setting up backlinks which caused some pages not to load +* FIX: Unhandled exception when cite ref was not found ## Release 1.4.2 diff --git a/pwabuilder-sw.js b/pwabuilder-sw.js index b1e13373..d6373389 100644 --- a/pwabuilder-sw.js +++ b/pwabuilder-sw.js @@ -4,7 +4,7 @@ // App version number - ENSURE IT MATCHES VALUE IN init.js // DEV: Changing this will cause the browser to recognize that the Service Worker has changed, and it will download and // install a new copy -const appVersion = '1.4.3-rc3'; +const appVersion = '1.4.3-rc4'; // Kiwix ZIM Archive Download Server in regex form // DEV: The server URL is defined in init.js, but is not available to us in SW diff --git a/www/index.html b/www/index.html index e40a8804..6143d957 100644 --- a/www/index.html +++ b/www/index.html @@ -127,6 +127,8 @@
  • Fix bug which failed to detect images correctly in new tab
  • Touch-zoom of contents of iframe no longer blanks part of the display
  • Fixed broken zoom of contents of iframe (with UI buttons) in Internet Explorer
  • +
  • Enabled search with wildcards '.*', '.+' or regex syntax '(?:my_regular_expression)': NB search must begin with normal alphanumeric string
  • +
  • Fixed bug setting up backlinks which caused some pages not to load
  • Full changelog...

    diff --git a/www/js/app.js b/www/js/app.js index 1b35b64a..39edd179 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -3588,9 +3588,14 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett //Setup endnote backlinks if the ZIM doesn't have any htmlArticle = htmlArticle.replace(/]+id=["']cite[-_]note[-_]([^"']+)[^>]+>(?![^/]+?[↑^])/ig, function (match, id) { - var fnSearchRegxp = new RegExp('id=["' + "'](cite[-_]ref[-_]" + id.replace(/[-_()+]/g, "[-_()]+") + '[^"' + "']*)", 'i'); - var fnReturnMatch = htmlArticle.match(fnSearchRegxp); - var fnReturnID = fnReturnMatch ? fnReturnMatch[1] : ""; + var fnReturnMatch = ''; + try { + var fnSearchRegxp = new RegExp('id=["' + "'](cite[-_]ref[-_]" + id.replace(/[-_()+?]/g, "[-_()]+?") + '[^"' + "']*)", 'i'); + fnReturnMatch = htmlArticle.match(fnSearchRegxp); + } catch (err) { + console.error('Error constructiong regular expression in app.js', err); + } + var fnReturnID = fnReturnMatch ? fnReturnMatch[1] : ''; return match + '\r\n'; }); @@ -3823,8 +3828,8 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett reference.addEventListener("click", function (obj) { var refID = obj.target.hash || obj.target.parentNode.hash; if (!refID) return; - refID = refID.replace(/#/, ""); - var refLocation = articleDocument.getElementById(refID); + var refLocation = docBody.querySelector(refID); + if (!refLocation) return; // In some ZIMs the id is in the parent node or in the parent of the parent var returnID = obj.target.id || obj.target.parentNode.id || obj.target.parentNode.parentNode.id; // Add backlink to refLocation if missing diff --git a/www/js/init.js b/www/js/init.js index bfdf7593..25334d6c 100644 --- a/www/js/init.js +++ b/www/js/init.js @@ -49,7 +49,7 @@ var params = {}; */ var appstate = {}; /******** UPDATE VERSION IN pwabuilder-sw.js TO MATCH VERSION AND CHECK PWASERVER BELOW!!!!!!! *******/ -params['version'] = "1.4.3-rc3"; //DEV: Manually update this version when there is a new release: it is compared to the Settings Store "version" in order to show first-time info, and the cookie is updated in app.js +params['version'] = "1.4.3-rc4"; //DEV: Manually update this version when there is a new release: it is compared to the Settings Store "version" in order to show first-time info, and the cookie is updated in app.js /******* UPDATE THIS ^^^^^^ IN service worker AND PWA-SERVER BELOW !! ********************/ params['packagedFile'] = getSetting('packagedFile') || "wikipedia_en_100_maxi_2021-05.zim"; //For packaged Kiwix JS (e.g. with Wikivoyage file), set this to the filename (for split files, give the first chunk *.zimaa) and place file(s) in default storage params['archivePath'] = "archives"; //The directory containing the packaged archive(s) (relative to app's root directory) diff --git a/www/js/lib/zimArchive.js b/www/js/lib/zimArchive.js index 0be505a7..29c0e26b 100644 --- a/www/js/lib/zimArchive.js +++ b/www/js/lib/zimArchive.js @@ -230,7 +230,7 @@ define(['zimfile', 'zimDirEntry', 'util', 'utf8'], prefixVariants = prefixVariants.slice(1); search.resultSize = resultSize - dirEntries.length; // Search window sets an upper limit on how many matching dirEntries will be scanned in a full index search - var searchWindow = search.rgxPrefix ? 250000 : resultSize; + var searchWindow = search.rgxPrefix ? 10000 * resultSize : resultSize; that.findDirEntriesWithPrefixCaseSensitive(prefix, searchWindow, search, function (newDirEntries, idx, interim) { if (search.status === 'cancelled') return callback([], search.status);