diff --git a/core/modules/simpletest/src/TestBase.php b/core/modules/simpletest/src/TestBase.php index c3862bc..171df78 100644 --- a/core/modules/simpletest/src/TestBase.php +++ b/core/modules/simpletest/src/TestBase.php @@ -1304,16 +1304,14 @@ public function randomString($length = 8) { if ($length < 3) { return $this->getRandomGenerator()->string($length, TRUE, array($this, 'randomStringValidate')); } + // To prevent the introduction of random test failures, ensure that the // returned string contains a character that needs to be escaped in HTML by - // splitting the length in half and injecting an ampersand into it. - $first = floor($length / 2); - $last = $length - $first - 1; - $parts = array(); - foreach (array($first, $last) as $length) { - $parts[] = $this->getRandomGenerator()->string($length, TRUE, array($this, 'randomStringValidate')); - } - return implode('&', $parts); + // injecting an ampersand into it. + $replacement_pos = floor($length / 2); + // Remove 1 from the length to account for the ampersand character. + $string = $this->getRandomGenerator()->string($length - 1, TRUE, array($this, 'randomStringValidate')); + return substr_replace($string, '&', $replacement_pos, 0); } /**