diff options
Diffstat (limited to 'modules/search')
-rw-r--r-- | modules/search/search.admin.inc | 3 | ||||
-rw-r--r-- | modules/search/search.module | 7 | ||||
-rw-r--r-- | modules/search/search.test | 26 |
3 files changed, 34 insertions, 2 deletions
diff --git a/modules/search/search.admin.inc b/modules/search/search.admin.inc index fda14ee7b..a609485ac 100644 --- a/modules/search/search.admin.inc +++ b/modules/search/search.admin.inc @@ -95,7 +95,8 @@ function search_admin_settings($form) { '#default_value' => variable_get('minimum_word_size', 3), '#size' => 5, '#maxlength' => 3, - '#description' => t('The number of characters a word has to be to be indexed. A lower setting means better search result ranking, but also a larger database. Each search query must contain at least one keyword that is this size (or longer).') + '#description' => t('The number of characters a word has to be to be indexed. A lower setting means better search result ranking, but also a larger database. Each search query must contain at least one keyword that is this size (or longer).'), + '#element_validate' => array('element_validate_integer_positive'), ); $form['indexing_settings']['overlap_cjk'] = array( '#type' => 'checkbox', diff --git a/modules/search/search.module b/modules/search/search.module index 915c96fb2..910cb6520 100644 --- a/modules/search/search.module +++ b/modules/search/search.module @@ -68,7 +68,7 @@ function search_help($path, $arg) { case 'admin/help#search': $output = ''; $output .= '<h3>' . t('About') . '</h3>'; - $output .= '<p>' . t('The Search module provides the ability to index and search for content by exact keywords, and for users by username or e-mail. For more information, see the online handbook entry for <a href="@search-module">Search module</a>.', array('@search-module' => 'http://drupal.org/handbook/modules/search/', '@search' => url('search'))) . '</p>'; + $output .= '<p>' . t('The Search module provides the ability to index and search for content by exact keywords, and for users by username or e-mail. For more information, see the online handbook entry for <a href="@search-module">Search module</a>.', array('@search-module' => 'http://drupal.org/documentation/modules/search/', '@search' => url('search'))) . '</p>'; $output .= '<h3>' . t('Uses') . '</h3>'; $output .= '<dl>'; $output .= '<dt>' . t('Searching content and users') . '</dt>'; @@ -1293,6 +1293,11 @@ function search_simplify_excerpt_match($key, $text, $offset, $boundary) { $simplified_key = search_simplify($key); $simplified_text = search_simplify($text); + // Return immediately if simplified key or text are empty. + if (!$simplified_key || !$simplified_text) { + return FALSE; + } + // Check if we have a match after simplification in the text. if (!preg_match('/' . $boundary . $simplified_key . $boundary . '/iu', $simplified_text, $match, PREG_OFFSET_CAPTURE, $offset)) { return FALSE; diff --git a/modules/search/search.test b/modules/search/search.test index ca1dd24a3..eeb6bf21b 100644 --- a/modules/search/search.test +++ b/modules/search/search.test @@ -1461,6 +1461,17 @@ class SearchConfigSettingsForm extends DrupalWebTestCase { $this->assertText(t('The index will be rebuilt')); $this->drupalGet('admin/config/search/settings'); $this->assertText(t('There is 1 item left to index.')); + + // Test that the form saves with the default values. + $this->drupalPost('admin/config/search/settings', array(), t('Save configuration')); + $this->assertText(t('The configuration options have been saved.'), 'Form saves with the default values.'); + + // Test that the form does not save with an invalid word length. + $edit = array( + 'minimum_word_size' => $this->randomName(3), + ); + $this->drupalPost('admin/config/search/settings', $edit, t('Save configuration')); + $this->assertNoText(t('The configuration options have been saved.'), 'Form does not save with an invalid word length.'); } /** @@ -1639,6 +1650,21 @@ class SearchExcerptTestCase extends DrupalUnitTestCase { $result = preg_replace('| +|', ' ', search_excerpt('"abc def"', $text)); $this->assertTrue(strpos($result, '<strong>abc,def</strong>') !== FALSE, 'Phrase with keyword simplified into two separate words is highlighted with simplified match'); + + // Test phrases with characters which are being truncated. + $result = preg_replace('| +|', ' ', search_excerpt('"ipsum _"', $text)); + $this->assertTrue(strpos($result, '<strong>ipsum </strong>') !== FALSE, 'Only valid part of the phrase is highlighted and invalid part containing "_" is ignored.'); + + $result = preg_replace('| +|', ' ', search_excerpt('"ipsum 0000"', $text)); + $this->assertTrue(strpos($result, '<strong>ipsum </strong>') !== FALSE, 'Only valid part of the phrase is highlighted and invalid part "0000" is ignored.'); + + // Test combination of the valid keyword and keyword containing only + // characters which are being truncated during simplification. + $result = preg_replace('| +|', ' ', search_excerpt('ipsum _', $text)); + $this->assertTrue(strpos($result, '<strong>ipsum</strong>') !== FALSE, 'Only valid keyword is highlighted and invalid keyword "_" is ignored.'); + + $result = preg_replace('| +|', ' ', search_excerpt('ipsum 0000', $text)); + $this->assertTrue(strpos($result, '<strong>ipsum</strong>') !== FALSE, 'Only valid keyword is highlighted and invalid keyword "0000" is ignored.'); } } |