diff options
author | David Rothstein <drothstein@gmail.com> | 2014-11-01 13:21:52 -0400 |
---|---|---|
committer | David Rothstein <drothstein@gmail.com> | 2014-11-01 13:21:52 -0400 |
commit | 6b7514afd2f03f3543d7c84e77cc97fa1d84dbb4 (patch) | |
tree | 5e8205a6cf1e734f8e2c30db9be64b2a598f537b /includes | |
parent | 3a4f085dfbf48a12d364b3aa80d0ecd336eb23e9 (diff) | |
download | brdo-6b7514afd2f03f3543d7c84e77cc97fa1d84dbb4.tar.gz brdo-6b7514afd2f03f3543d7c84e77cc97fa1d84dbb4.tar.bz2 |
Issue #829464 by Berdir, klausi, sepgil | Heine: Fixed orderby() should verify that the sort direction is always ASC or DESC.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/database/select.inc | 5 | ||||
-rw-r--r-- | includes/tablesort.inc | 7 |
2 files changed, 7 insertions, 5 deletions
diff --git a/includes/database/select.inc b/includes/database/select.inc index 70c03a283..3abd205c9 100644 --- a/includes/database/select.inc +++ b/includes/database/select.inc @@ -377,7 +377,8 @@ interface SelectQueryInterface extends QueryConditionInterface, QueryAlterableIn * @param $field * The field on which to order. * @param $direction - * The direction to sort. Legal values are "ASC" and "DESC". + * The direction to sort. Legal values are "ASC" and "DESC". Any other value + * will be converted to "ASC". * @return SelectQueryInterface * The called object. */ @@ -1384,6 +1385,8 @@ class SelectQuery extends Query implements SelectQueryInterface { } public function orderBy($field, $direction = 'ASC') { + // Only allow ASC and DESC, default to ASC. + $direction = strtoupper($direction) == 'DESC' ? 'DESC' : 'ASC'; $this->order[$field] = $direction; return $this; } diff --git a/includes/tablesort.inc b/includes/tablesort.inc index e589526c6..e9c280686 100644 --- a/includes/tablesort.inc +++ b/includes/tablesort.inc @@ -46,10 +46,9 @@ class TableSort extends SelectQueryExtender { // Based on code from db_escape_table(), but this can also contain a dot. $field = preg_replace('/[^A-Za-z0-9_.]+/', '', $ts['sql']); - // Sort order can only be ASC or DESC. - $sort = drupal_strtoupper($ts['sort']); - $sort = in_array($sort, array('ASC', 'DESC')) ? $sort : ''; - $this->orderBy($field, $sort); + // orderBy() will ensure that only ASC/DESC values are accepted, so we + // don't need to sanitize that here. + $this->orderBy($field, $ts['sort']); } return $this; } |