diff options
-rw-r--r-- | includes/database/select.inc | 4 | ||||
-rw-r--r-- | includes/file.inc | 2 | ||||
-rw-r--r-- | includes/unicode.inc | 4 | ||||
-rw-r--r-- | modules/blogapi/blogapi.module | 4 | ||||
-rw-r--r-- | modules/filter/filter.module | 2 | ||||
-rw-r--r-- | modules/profile/profile.module | 4 | ||||
-rw-r--r-- | modules/simpletest/tests/database_test.test | 45 |
7 files changed, 52 insertions, 13 deletions
diff --git a/includes/database/select.inc b/includes/database/select.inc index 3d1074773..e24b54cc2 100644 --- a/includes/database/select.inc +++ b/includes/database/select.inc @@ -670,9 +670,11 @@ class SelectQuery extends Query implements QueryConditionInterface, QueryAlterab // ORDER BY if ($this->order) { $query .= "\nORDER BY "; + $fields = array(); foreach ($this->order as $field => $direction) { - $query .= $field . ' ' . $direction . ' '; + $fields[] = $field . ' ' . $direction; } + $query .= implode(', ', $fields); } // RANGE is database specific, so we can't do it here. diff --git a/includes/file.inc b/includes/file.inc index 68fa2c23b..1be451823 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -658,7 +658,7 @@ function file_validate_extensions($file, $extensions) { // Bypass validation for uid = 1. if ($user->uid != 1) { - $regex = '/\.(' . ereg_replace(' +', '|', preg_quote($extensions)) . ')$/i'; + $regex = '/\.(' . preg_replace('/ +/', '|', preg_quote($extensions)) . ')$/i'; if (!preg_match($regex, $file->filename)) { $errors[] = t('Only files with the following extensions are allowed: %files-allowed.', array('%files-allowed' => $extensions)); } diff --git a/includes/unicode.inc b/includes/unicode.inc index 93a522d09..b01e3bcfd 100644 --- a/includes/unicode.inc +++ b/includes/unicode.inc @@ -135,7 +135,7 @@ function drupal_xml_parser_create(&$data) { } // Check for an encoding declaration in the XML prolog if no BOM was found. - if (!$bom && ereg('^<\?xml[^>]+encoding="([^"]+)"', $data, $match)) { + if (!$bom && preg_match('/^<\?xml[^>]+encoding="(.+?)"/', $data, $match)) { $encoding = $match[1]; } @@ -145,7 +145,7 @@ function drupal_xml_parser_create(&$data) { $out = drupal_convert_to_utf8($data, $encoding); if ($out !== FALSE) { $encoding = 'utf-8'; - $data = ereg_replace('^(<\?xml[^>]+encoding)="([^"]+)"', '\\1="utf-8"', $out); + $data = preg_replace('/^(<\?xml[^>]+encoding)="(.+?)"/', '\\1="utf-8"', $out); } else { watchdog('php', 'Could not convert XML encoding %s to UTF-8.', array('%s' => $encoding), WATCHDOG_WARNING); diff --git a/modules/blogapi/blogapi.module b/modules/blogapi/blogapi.module index 6272a0be7..56408dbb4 100644 --- a/modules/blogapi/blogapi.module +++ b/modules/blogapi/blogapi.module @@ -558,9 +558,9 @@ function blogapi_validate_user($username, $password) { * For the blogger API, extract the node title from the contents field. */ function blogapi_blogger_title(&$contents) { - if (eregi('<title>([^<]*)</title>', $contents, $title)) { + if (preg_match('/<title>(.*?)<\/title>/i', $contents, $title)) { $title = strip_tags($title[0]); - $contents = ereg_replace('<title>[^<]*</title>', '', $contents); + $contents = preg_replace('/<title>.*?<\/title>/i', '', $contents); } else { list($title, $contents) = explode("\n", $contents, 2); diff --git a/modules/filter/filter.module b/modules/filter/filter.module index 3185ba6e0..198c828e3 100644 --- a/modules/filter/filter.module +++ b/modules/filter/filter.module @@ -869,7 +869,7 @@ function _filter_autop($text) { if ($i % 2) { // Opening or closing tag? $open = ($chunk[1] != '/'); - list($tag) = split('[ >]', substr($chunk, 2 - $open), 2); + list($tag) = preg_split('/[ >]/', substr($chunk, 2 - $open), 2); if (!$ignore) { if ($open) { $ignore = TRUE; diff --git a/modules/profile/profile.module b/modules/profile/profile.module index 36b653cea..c5ade96b1 100644 --- a/modules/profile/profile.module +++ b/modules/profile/profile.module @@ -276,7 +276,7 @@ function profile_view_field($user, $field) { ); return strtr($format, $replace); case 'list': - $values = split("[,\n\r]", $value); + $values = preg_split("/[,\n\r]/", $value); $fields = array(); foreach ($values as $value) { if ($value = trim($value)) { @@ -387,7 +387,7 @@ function profile_form_profile($edit, $user, $category, $register = FALSE) { break; case 'selection': $options = $field->required ? array() : array('--'); - $lines = split("[,\n\r]", $field->options); + $lines = preg_split("/[,\n\r]/", $field->options); foreach ($lines as $line) { if ($line = trim($line)) { $options[$line] = $line; diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test index 725812195..5ce1f8db1 100644 --- a/modules/simpletest/tests/database_test.test +++ b/modules/simpletest/tests/database_test.test @@ -198,7 +198,7 @@ class DatabaseFetch2TestCase extends DatabaseTestCase { function getInfo() { return array( - 'name' => t('Fetch tests, Part 2'), + 'name' => t('Fetch tests, part 2'), 'description' => t('Test the Database system\'s various fetch capabilities.'), 'group' => t('Database'), ); @@ -455,7 +455,7 @@ class DatabaseInsertDefaultsTestCase extends DatabaseTestCase { function getInfo() { return array( - 'name' => t('Insert tests, Default fields'), + 'name' => t('Insert tests, default fields'), 'description' => t('Test the Insert query builder with default values.'), 'group' => t('Database'), ); @@ -968,7 +968,7 @@ class DatabaseSelectOrderedTestCase extends DatabaseTestCase { function getInfo() { return array( - 'name' => t('Select tests, Ordered'), + 'name' => t('Select tests, ordered'), 'description' => t('Test the Select query builder.'), 'group' => t('Database'), ); @@ -1001,6 +1001,43 @@ class DatabaseSelectOrderedTestCase extends DatabaseTestCase { } /** + * Test multiple order by. + */ + function testSimpleSelectMultiOrdered() { + try { + $query = db_select('test'); + $name_field = $query->addField('test', 'name'); + $age_field = $query->addField('test', 'age', 'age'); + $job_field = $query->addField('test', 'job'); + $query->orderBy($job_field); + $query->orderBy($age_field); + $result = $query->execute(); + + $num_records = 0; + $expected = array( + array('Ringo', 28, 'Drummer'), + array('John', 25, 'Singer'), + array('George', 27, 'Singer'), + array('Paul', 26, 'Songwriter'), + ); + $results = $result->fetchAll(PDO::FETCH_NUM); + foreach ($expected as $k => $record) { + $num_records++; + foreach ($record as $kk => $col) { + if ($expected[$k][$kk] != $results[$k][$kk]) { + $this->assertTrue(FALSE, t('Results returned in correct order.')); + } + } + } + $this->assertEqual($num_records, 4, t('Returned the correct number of rows.')); + } + catch(Exception $e) { + $this->assertTrue(FALSE, $e->getMessage()); + } + } + + + /** * Test order by descending. */ function testSimpleSelectOrderedDesc() { @@ -1034,7 +1071,7 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase { function getInfo() { return array( - 'name' => t('Select tests, Complex'), + 'name' => t('Select tests, complex'), 'description' => t('Test the Select query builder with more complex queries.'), 'group' => t('Database'), ); |