]> BookStack Code Mirror - bookstack/commitdiff
Fixed issue with searching invalid chars and page-content compiliation
authorDan Brown <redacted>
Tue, 29 Dec 2015 15:37:13 +0000 (15:37 +0000)
committerDan Brown <redacted>
Tue, 29 Dec 2015 15:37:13 +0000 (15:37 +0000)
app/Entity.php
app/Repos/BookRepo.php
app/Repos/ChapterRepo.php
app/Repos/PageRepo.php
resources/views/pages/page-display.blade.php
tests/EntityTest.php

index 5ccc016a330a897b45742b1e42920b57533a9bfe..3d1c4ad58a0ad912e7dbc078195cbb02c6baad6e 100644 (file)
@@ -115,12 +115,12 @@ abstract class Entity extends Model
     {
         $termString = '';
         foreach ($terms as $term) {
-            $termString .= $term . '* ';
+            $termString .= htmlentities($term) . '* ';
         }
         $fields = implode(',', $fieldsToSearch);
         $termStringEscaped = \DB::connection()->getPdo()->quote($termString);
         $search = static::addSelect(\DB::raw('*, MATCH(name) AGAINST('.$termStringEscaped.' IN BOOLEAN MODE) AS title_relevance'));
-        $search = $search->whereRaw('MATCH(' . $fields . ') AGAINST(? IN BOOLEAN MODE)', [$termString]);
+        $search = $search->whereRaw('MATCH(' . $fields . ') AGAINST(? IN BOOLEAN MODE)', [$termStringEscaped]);
 
         // Add additional where terms
         foreach ($wheres as $whereTerm) {
index 031e3b44c18d6b708108c9f2a3bf66ee08f4cf6a..a57050ce2bede8748ee864d42706e8b8d4b90c62 100644 (file)
@@ -222,9 +222,9 @@ class BookRepo
      */
     public function getBySearch($term)
     {
-        $terms = explode(' ', preg_quote(trim($term)));
+        $terms = explode(' ', $term);
         $books = $this->book->fullTextSearch(['name', 'description'], $terms);
-        $words = join('|', $terms);
+        $words = join('|', explode(' ', preg_quote(trim($term), '/')));
         foreach ($books as $book) {
             //highlight
             $result = preg_replace('#' . $words . '#iu', "<span class=\"highlight\">\$0</span>", $book->getExcerpt(100));
index 1e4996a407c3c50a4e17e546c25979273e5dc4cd..3824e6982ab008047962862ed883c4fd68288a8d 100644 (file)
@@ -129,9 +129,9 @@ class ChapterRepo
      */
     public function getBySearch($term, $whereTerms = [])
     {
-        $terms = explode(' ', preg_quote(trim($term)));
+        $terms = explode(' ', $term);
         $chapters = $this->chapter->fullTextSearch(['name', 'description'], $terms, $whereTerms);
-        $words = join('|', $terms);
+        $words = join('|', explode(' ', preg_quote(trim($term), '/')));
         foreach ($chapters as $chapter) {
             //highlight
             $result = preg_replace('#' . $words . '#iu', "<span class=\"highlight\">\$0</span>", $chapter->getExcerpt(100));
index e049ae57b67a6cde77d18d07683f349f5891e817..05052432efd577fcd5d6d95a2c33675f9e974109 100644 (file)
@@ -177,11 +177,11 @@ class PageRepo
      */
     public function getBySearch($term, $whereTerms = [])
     {
-        $terms = explode(' ', preg_quote(trim($term)));
+        $terms = explode(' ', $term);
         $pages = $this->page->fullTextSearch(['name', 'text'], $terms, $whereTerms);
 
         // Add highlights to page text.
-        $words = join('|', $terms);
+        $words = join('|', explode(' ', preg_quote(trim($term), '/')));
         //lookahead/behind assertions ensures cut between words
         $s = '\s\x00-/:-@\[-`{-~'; //character set for start/end of words
 
index 8d3625db89a490dd062f2c07495957ba28603a47..13db89d262567913ad21826ce16f9bfb9be4e832 100644 (file)
@@ -1,3 +1,5 @@
-<h1 id="bkmrk-page-title">{{$page->name}}</h1>
+<div v-pre>
+    <h1 id="bkmrk-page-title">{{$page->name}}</h1>
 
-{!! $page->html !!}
\ No newline at end of file
+    {!! $page->html !!}
+</div>
\ No newline at end of file
index 07553e7dc26268825962ce8206add64218d3dee3..b883e854399cc3d155d2d2e4c41f7acb68a821ef 100644 (file)
@@ -170,6 +170,16 @@ class EntityTest extends TestCase
             ->seePageIs($page->getUrl());
     }
 
+    public function testInvalidPageSearch()
+    {
+        $this->asAdmin()
+            ->visit('/')
+            ->type('<p>test</p>', 'term')
+            ->press('header-search-box-button')
+            ->see('Search Results')
+            ->seeStatusCode(200);
+    }
+
 
     public function testEntitiesViewableAfterCreatorDeletion()
     {