diff --git a/core/lib/Drupal/Component/Utility/Random.php b/core/lib/Drupal/Component/Utility/Random.php
index df989c0..4aed128 100644
--- a/core/lib/Drupal/Component/Utility/Random.php
+++ b/core/lib/Drupal/Component/Utility/Random.php
@@ -63,7 +63,7 @@ public static function string($length = 8, $unique = FALSE) {
       }
       $str = '';
       for ($i = 0; $i < $length; $i++) {
-        $str .= chr(mt_rand(32, 126));
+        $str .= chr(mt_rand(33, 126));
       }
       $counter++;
     } while ($unique && isset(static::$strings[$str]));
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/Tests/RandomStringTest.php b/core/modules/simpletest/lib/Drupal/simpletest/Tests/RandomStringTest.php
new file mode 100644
index 0000000..d1dc465
--- /dev/null
+++ b/core/modules/simpletest/lib/Drupal/simpletest/Tests/RandomStringTest.php
@@ -0,0 +1,83 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\system\Tests\Entity\RandomStringTest.
+ */
+
+namespace Drupal\simpletest\Tests;
+
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Tests for entity operations, that they can be altered.
+ */
+class RandomStringTest extends WebTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array('entity_test');
+
+  /**
+   * @var $web_user
+   *   The user to login and verify that roles have been created.
+   */
+  protected $web_user;
+
+  public static function getInfo() {
+    return array(
+      'name' => 'RandomString functionality',
+      'description' => "Test SimpleTest's xpath on randomly generated strings",
+      'group' => 'SimpleTest'
+    );
+  }
+
+  public function setUp() {
+    parent::setUp();
+
+    // Create and login user.
+    $this->web_user = $this->drupalCreateUser(array(
+      'administer permissions',
+    ));
+    $this->drupalLogin($this->web_user);
+  }
+
+  /**
+   * Checks that the UI will display a link created within the parameters of
+   * WebTestBase::RandomString.
+   *
+   * @see entity_test_entity_operation_alter()
+   */
+  public function testXpathRandomString() {
+
+    // Create roles.
+    $role_names = array(
+      ' curry paste',
+      'curry paste ',
+      'curry paste',
+      'thai green curry paste',
+      'Number\\9',
+      'Number\9',
+      'Number9',
+      'Number9\\',
+      '$7@|{v$S',
+    );
+
+    foreach ($role_names as $role_name) {
+      $this->drupalCreateRole(array('administer permissions'), NULL, trim($role_name));
+    }
+
+    // Check that role listing contain our test_operation operation.
+    $this->drupalGet('admin/people/roles');
+    $roles = user_roles();
+    foreach ($roles as $role) {
+      $uri = $role->uri();
+      $this->assertLinkByHref($uri['path'] . '/test_operation');
+      $this->assertLink(format_string('Test Operation: @label', array('@label' => $role->label())));
+    }
+  }
+
+}
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index 8e295b3..07b8622 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -1877,7 +1877,7 @@ protected function buildXPathQuery($xpath, array $args = array()) {
         // Return the string.
         $value = count($parts) > 1 ? 'concat(' . implode(', \'"\', ', $parts) . ')' : $parts[0];
       }
-      $xpath = preg_replace('/' . preg_quote($placeholder) . '\b/', $value, $xpath);
+      $xpath = str_replace($placeholder, $value, $xpath);
     }
     return $xpath;
   }
