diff --git a/core/lib/Drupal/Component/Utility/UrlHelper.php b/core/lib/Drupal/Component/Utility/UrlHelper.php index 553a152..3c29d40 100644 --- a/core/lib/Drupal/Component/Utility/UrlHelper.php +++ b/core/lib/Drupal/Component/Utility/UrlHelper.php @@ -37,13 +37,17 @@ class UrlHelper { * @ingroup php_wrappers */ public static function buildQuery(array $query) { - // Previous versions of Drupal created query arguments with NULL values but - // http_build_query throws them away. This provides an equivalent - // functionality. + // Do some conversions to match previous implementations. array_walk_recursive($query, function (&$value, $key) { + // Previous versions of Drupal created query arguments with NULL values + // but http_build_query throws them away. Convert to empty string. if (!isset($value)) { $value = ''; } + // Previous versions of Drupal cast objects to strings. + if (!is_scalar($value)) { + $value = (string) $value; + } }); return http_build_query($query, '', '&', PHP_QUERY_RFC3986); } diff --git a/core/modules/system/src/Tests/Database/SelectTableSortDefaultTest.php b/core/modules/system/src/Tests/Database/SelectTableSortDefaultTest.php index 7ccbbb5..f1505c8 100644 --- a/core/modules/system/src/Tests/Database/SelectTableSortDefaultTest.php +++ b/core/modules/system/src/Tests/Database/SelectTableSortDefaultTest.php @@ -32,8 +32,8 @@ function testTableSortQuery() { $first = array_shift($data->tasks); $last = array_pop($data->tasks); - $this->assertEqual($first->task, $sort['first'], 'Items appear in the correct order.'); - $this->assertEqual($last->task, $sort['last'], 'Items appear in the correct order.'); + $this->assertEqual($first->task, $sort['first'], format_string('Items appear in the correct order sorting by @field @sort.', array('@field' => $sort['field'], '@sort' => $sort['sort']))); + $this->assertEqual($last->task, $sort['last'], format_string('Items appear in the correct order sorting by @field @sort.', array('@field' => $sort['field'], '@sort' => $sort['sort']))); } } diff --git a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php index 3e7fe6c..93fe7dd 100644 --- a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\Component\Utility; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\UrlHelper; use Drupal\Tests\UnitTestCase; @@ -49,6 +50,10 @@ public function testBuildQuerySpecial() { // Parse string throws away the leading space in the key breaking our // generalized test. $this->assertEquals('%20%26%23%2F%2F%2B%2520%40%DB%9E=a', UrlHelper::buildQuery([' &#//+%20@۞' => 'a']), 'Key was properly encoded.'); + + // Ensure as a convenience we can put translatable and formatted markup + // objects into queries. + $this->assertEquals('a=foo', UrlHelper::buildQuery(['a' => new FormattableMarkup('foo', [])]), 'Objects cast as a string.'); } /**