diff --git a/modules/search/search.module b/modules/search/search.module index 334e8c14c5c67612bbf5e1d0bca89509bbaec703..2ab3a4210d27fe22361ce4449475649289a9d9a3 100644 --- a/modules/search/search.module +++ b/modules/search/search.module @@ -372,10 +372,13 @@ function search_simplify($text) { // Readable regexp: ([number]+)[punctuation]+(?=[number]) $text = preg_replace('/([' . PREG_CLASS_NUMBERS . ']+)[' . PREG_CLASS_PUNCTUATION . ']+(?=[' . PREG_CLASS_NUMBERS . '])/u', '\1', $text); + // Multiple dot and dash groups are word boundaries and replaced with space. + // No need to use the unicode modifer here because 0-127 ASCII characters + // can't match higher UTF-8 characters as the leftmost bit of those are 1. + $text = preg_replace('/[.-]{2,}/', ' ', $text); + // The dot, underscore and dash are simply removed. This allows meaningful - // search behavior with acronyms and URLs. No need to use the unicode modifer - // here because 0-127 ASCII characters can't match higher UTF-8 characters as - // the leftmost bit of those are 1. + // search behavior with acronyms and URLs. See unicode note directly above. $text = preg_replace('/[._-]+/', '', $text); // With the exception of the rules above, we consider all punctuation, diff --git a/modules/search/search.test b/modules/search/search.test index ae93e76f8cc192eb8835301fa268296c8f248cc0..b6a72d0bda3e92a85abcb53064f28fd09923c9e1 100644 --- a/modules/search/search.test +++ b/modules/search/search.test @@ -935,22 +935,22 @@ class SearchCommentCountToggleTestCase extends DrupalWebTestCase { $this->drupalPost('', $edit, t('Search')); $this->assertNoText(t('0 comments'), t('Empty comment count does not display for nodes with comment status set to Hidden')); $this->assertNoText(t('1 comment'), t('Non-empty comment count does not display for nodes with comment status set to Hidden')); - } + } } /** - * Test search_simplify() on every Unicode character. + * Test search_simplify() on every Unicode character, and some other cases. */ class SearchSimplifyTestCase extends DrupalWebTestCase { public static function getInfo() { return array( 'name' => 'Search simplify', - 'description' => 'Check that simplification works as intended.', + 'description' => 'Check that the search_simply() function works as intended.', 'group' => 'Search', ); } - function testSearchSimplify() { + function testSearchSimplifyUnicode() { $input = file_get_contents(DRUPAL_ROOT . '/modules/search/tests/UnicodeTest.txt'); $strings = explode(chr(10), $input); foreach ($strings as $key => $string) { @@ -969,6 +969,23 @@ class SearchSimplifyTestCase extends DrupalWebTestCase { // Diff really does not like files starting with \0 so test it separately. $this->assertIdentical(' ', search_simplify($string), t('Search simplify works for ASCII control characters.')); } + + /** + * Tests that search_simplify() does the right thing with punctuation. + */ + function testSearchSimplifyPunctuation() { + $cases = array( + array('20.03/94-28,876', '20039428876', 'Punctuation removed from numbers'), + array('great...drupal--module', 'great drupal module', 'Multiple dot and dashes are word boundaries'), + array('very_great-drupal.module', 'verygreatdrupalmodule', 'Single dot, dash, underscore are removed'), + array('regular,punctuation;word', 'regular punctuation word', 'Punctuation is a word boundary'), + ); + + foreach ($cases as $case) { + $out = trim(search_simplify($case[0])); + $this->assertEqual($out, $case[1], $case[2]); + } + } } /** diff --git a/profiles/minimal/minimal.profile b/profiles/minimal/minimal.profile index 5fd06c3fc05af5529118f21f377c326fad683937..7f0bf8a98ab4269bc72637d05d7a88916f75779d 100644 --- a/profiles/minimal/minimal.profile +++ b/profiles/minimal/minimal.profile @@ -2,10 +2,11 @@ // $Id$ /** - * Implements hook_form_alter(). + * Implements hook_form_FORM_ID_alter(). * * Allows the profile to alter the site configuration form. */ function minimal_form_install_configure_form_alter(&$form, $form_state) { + // Pre-populate the site name with the server name. $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME']; } diff --git a/profiles/standard/standard.profile b/profiles/standard/standard.profile index d8203d0e5f24234017799b2bbf1603eeef515a88..9180e95802e2ca6ad6eadea50e7e38990ceab263 100644 --- a/profiles/standard/standard.profile +++ b/profiles/standard/standard.profile @@ -2,13 +2,11 @@ // $Id$ /** - * Implements hook_form_alter(). + * Implements hook_form_FORM_ID_alter(). * * Allows the profile to alter the site configuration form. */ -function standard_form_alter(&$form, $form_state, $form_id) { - if ($form_id == 'install_configure_form') { - // Set default for site name field. - $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME']; - } +function standard_form_install_configure_form_alter(&$form, $form_state) { + // Pre-populate the site name with the server name. + $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME']; }