viewgit/inc/functions.php:22 Function utf8_encode() is deprecated [8192]

Fix result where Unit testts viewable even when turned off, fixed bugs in iterators introduced when adding directions to iterators, a=chris

Chris Pollett [2019-12-19 22:Dec:th]
Fix result where Unit testts viewable even when turned off, fixed bugs in iterators introduced when adding directions to iterators, a=chris
Filename
src/index.php
src/library/WebArchiveBundle.php
src/library/index_bundle_iterators/DocIterator.php
src/library/index_bundle_iterators/WordIterator.php
diff --git a/src/index.php b/src/index.php
index 397d2cda2..3a2eb8ab0 100644
--- a/src/index.php
+++ b/src/index.php
@@ -107,7 +107,10 @@ function bootstrap($web_site = null, $start_new_session = true)
      */
     $available_controllers = ["admin", "api", "archive",  "cache",
         "classifier", "crawl", "fetch", "group", "jobs", "machine", "resource",
-        "search", "static", "tests"];
+        "search", "static"];
+    if (C\DISPLAY_TESTS) {
+        $available_controllers[] = "tests";
+    }
     if (function_exists(C\NS_CONFIGS . "localControllers")) {
         $available_controllers = array_merge($available_controllers,
             C\localControllers());
@@ -134,11 +137,9 @@ function bootstrap($web_site = null, $start_new_session = true)
     }
     if (!in_array($controller_name, $available_controllers))
     {
-        if (C\WEB_ACCESS) {
-            $controller_name = "search";
-        } else {
-            $controller_name = "admin";
-        }
+        $controller_name = "static";
+        $_REQUEST['c'] = "static";
+        $_REQUEST['p'] = "404";
     }
     // if no profile exists we force the page to be the configuration page
     if (!C\PROFILE || (C\nsdefined("FIX_NAME_SERVER") && C\FIX_NAME_SERVER)) {
diff --git a/src/library/WebArchiveBundle.php b/src/library/WebArchiveBundle.php
index f23b4cb1e..049396369 100755
--- a/src/library/WebArchiveBundle.php
+++ b/src/library/WebArchiveBundle.php
@@ -116,7 +116,7 @@ class WebArchiveBundle
         //store/read archive description
         if (file_exists($dir_name."/description.txt")) {
             $info = unserialize(
-                file_get_contents($this->dir_name."/description.txt"));
+                file_get_contents($this->dir_name . "/description.txt"));
         } else {
             $this->version = C\DEFAULT_CRAWL_FORMAT;
         }
diff --git a/src/library/index_bundle_iterators/DocIterator.php b/src/library/index_bundle_iterators/DocIterator.php
index 052e33dfb..b85626736 100755
--- a/src/library/index_bundle_iterators/DocIterator.php
+++ b/src/library/index_bundle_iterators/DocIterator.php
@@ -244,8 +244,7 @@ class DocIterator extends IndexBundleIterator
             $pre_num_docs = ($is_ascending) ?
                 ($this->last_offset - $this->next_offset) / $doc_item_len :
                 $this->next_offset/$doc_item_len;
-            $num_docs = min($this->results_per_block,
-                );
+            $num_docs = min($this->results_per_block, $pre_num_docs);
             $this->next_offset = $this->current_offset;
             if ($is_ascending) {
                 $this->next_offset += $doc_item_len * $num_docs;
@@ -270,6 +269,7 @@ class DocIterator extends IndexBundleIterator
      */
     public function advance($gen_doc_offset = null)
     {
+        $is_ascending = ($this->direction == self::ASCENDING);
         $this->advanceSeenDocs();
         if (($is_ascending && $this->current_offset < $this->next_offset) ||
             (!$is_ascending && $this->current_offset > $this->next_offset)) {
diff --git a/src/library/index_bundle_iterators/WordIterator.php b/src/library/index_bundle_iterators/WordIterator.php
index 53f9d1f78..e5920a5ee 100644
--- a/src/library/index_bundle_iterators/WordIterator.php
+++ b/src/library/index_bundle_iterators/WordIterator.php
@@ -257,12 +257,13 @@ class WordIterator extends IndexBundleIterator
         }
         $ascending = ($this->direction == self::ASCENDING);
         if ($ascending) {
-            if ($this->generation_pointer == $this->num_generations - 1 &&
+            if (($this->generation_pointer >= $this->num_generations) ||
+                $this->generation_pointer == $this->num_generations - 1 &&
                 $this->current_offset > $this->last_offset) {
                 return -1;
             }
         } else {
-            if (($this->generation_pointer >= $this->num_generations)
+            if (($this->generation_pointer < 0)
                 || ($this->generation_pointer == 0 &&
                 $this->current_offset < $this->start_offset)) {
                 return -1;
@@ -274,7 +275,7 @@ class WordIterator extends IndexBundleIterator
             $index = IndexManager::getIndex($this->index_name);
             $index->setCurrentShard($this->current_generation, true);
             //the next call also updates next offset
-            $shard = $index->getCurrentShard();
+            $shard = $index->getCurrentShard(true);
             $pre_results = $shard->getPostingsSlice($this->start_offset,
                 $this->next_offset, $this->last_offset,
                 $this->results_per_block, $this->direction);
@@ -504,7 +505,7 @@ class WordIterator extends IndexBundleIterator
             ($this->current_offset > $this->last_offset ||
             $this->generation_pointer >= $this->num_generations) :
             ($this->current_offset < $this->start_offset||
-            $this->generation_pointer <= -1);
+            $this->generation_pointer < -1);
         if ($offset_check) {
             return -1;
         }
ViewGit