Fix misspelt continue; fix issue qith spelling suggestions, a=chris

Chris Pollett [2022-08-16 23:Aug:th]
Fix misspelt continue; fix issue qith spelling suggestions, a=chris
Filename
src/library/LocaleFunctions.php
src/library/processors/HtmlProcessor.php
src/scripts/suggest.js
src/views/elements/SearchbarElement.php
diff --git a/src/library/LocaleFunctions.php b/src/library/LocaleFunctions.php
index a2fc3d4b4..7769e102a 100755
--- a/src/library/LocaleFunctions.php
+++ b/src/library/LocaleFunctions.php
@@ -244,6 +244,12 @@ function guessLangEncoding($encoding)
  */
 function guessEncodingHtmlXml($html, $return_loc_info = false)
 {
+    /* sometimes the page will say it is other than UTF-8 even if it is
+       so do a quick check first
+     */
+    if (mb_check_encoding($html, 'UTF-8')) {
+        return 'UTF-8';
+    }
     // first try for XML encoding info
     preg_match("/\<\?xml[^\?]+encoding\=[\'\"]\s*(\S+)\s*[\'\"][^\?]+\?\>/",
         $html, $matches, PREG_OFFSET_CAPTURE);
diff --git a/src/library/processors/HtmlProcessor.php b/src/library/processors/HtmlProcessor.php
index c104f7e69..b571f140b 100755
--- a/src/library/processors/HtmlProcessor.php
+++ b/src/library/processors/HtmlProcessor.php
@@ -272,8 +272,9 @@ class HtmlProcessor extends TextProcessor
         $links_scores = [];
         $out_links = [];
         foreach ($links as $link_url => $link_text) {
+            // Avoid redirects in top-level links
             if (preg_match("/^Location/i", $link_text)) {
-                contnue;
+                continue;
             }
             $cld = UrlParser::getCompanyLevelDomain($url);
             if (stristr($link_url, $cld) === false ||
diff --git a/src/scripts/suggest.js b/src/scripts/suggest.js
index 67bb651b0..921bc06a5 100644
--- a/src/scripts/suggest.js
+++ b/src/scripts/suggest.js
@@ -715,6 +715,8 @@ function loadFiles()
 function spellCheck()
 {
     let reference_node;
+    let spell_link;
+    let csrf_token;
     if (document.getElementsByClassName) {
         reference_node = document.getElementsByClassName("search-results")[0];
     }
@@ -726,9 +728,9 @@ function spellCheck()
         if (!corrected_spell) {
             return;
         }
-        let logged_in = elt("csrf-token");
+        let logged_in = (elt("csrf-token") !== null);
         if (logged_in) {
-            let csrf_token = elt("csrf-token").value;
+            csrf_token = elt("csrf-token").value;
         }
         let its_value = elt("its-value").value;
         let query = elt("query-field").value;
@@ -769,10 +771,10 @@ function spellCheck()
         if (corrected_query.trim() != query.toLowerCase().trim()) {
             if (logged_in) {
                 let token_name = csrf_name;
-                let spell_link = "?" + token_name + "=" + csrf_token + "&q="
+                spell_link = "?" + token_name + "=" + csrf_token + "&q="
                     + corrected_query;
             } else {
-                let spell_link = "?q=" + corrected_query;
+                spell_link = "?q=" + corrected_query;
             }
             setDisplay('spell-check', true);
             corrected_spell.innerHTML = "<b>" + local_strings.spell
diff --git a/src/views/elements/SearchbarElement.php b/src/views/elements/SearchbarElement.php
index 94d8f568d..15a8521e6 100644
--- a/src/views/elements/SearchbarElement.php
+++ b/src/views/elements/SearchbarElement.php
@@ -97,12 +97,12 @@ class SearchbarElement extends Element
             <span class="<?=$subsearch_shift?>">
             <?php if (isset($data["SUBSEARCH"]) && $data["SUBSEARCH"] != "") {
                 ?><input type="hidden" name="s" value="<?=
-                $data['SUBSEARCH'] ?>" />
-            <?php } ?>
-            <?php if ($logged_in) { ?>
-            <input id="csrf-token" type="hidden" name="<?= C\CSRF_TOKEN ?>"
-                value="<?= $data[C\CSRF_TOKEN] ?>" />
-            <?php } ?>
+                $data['SUBSEARCH'] ?>" /><?php
+            }
+            if ($logged_in) {
+                ?><input id="csrf-token" type="hidden" name="<?=
+                    C\CSRF_TOKEN ?>" value="<?= $data[C\CSRF_TOKEN] ?>" /><?php
+            } ?>
             <input id="its-value" type="hidden" name="its" value="<?=
                 $data['its'] ?>" />
             <input type="search" autocapitalize="none" autocorrect="off" <?php
ViewGit