diff --git a/core/lib/Drupal/Core/Template/Attribute.php b/core/lib/Drupal/Core/Template/Attribute.php
index 076cfd3..b84cc79 100644
--- a/core/lib/Drupal/Core/Template/Attribute.php
+++ b/core/lib/Drupal/Core/Template/Attribute.php
@@ -7,7 +7,6 @@
 
 namespace Drupal\Core\Template;
 
-
 /**
  * A class that can be used for collecting then rendering HTML attributtes.
  *
@@ -17,7 +16,7 @@
  *  $attributes = new Attribute(array('id' => 'socks'));
  *  $attributes['class'] = array('black-cat', 'white-cat');
  *  $attributes['class'][] = 'black-white-cat';
- *  echo '<cat ' . $attributes . '>';
+ *  echo '<cat' . $attributes . '>';
  *  // Produces <cat id="socks" class="black-cat white-cat black-white-cat">
  * @endcode
  *
@@ -26,7 +25,7 @@
  *  $attributes = new Attribute(array('id' => 'socks'));
  *  $attributes['class'] = array('black-cat', 'white-cat');
  *  $attributes['class'][] = 'black-white-cat';
- *  echo '<cat class="cat ' . $attributes['class'] . '" ' . $attributes . '>';
+ *  echo '<cat class="cat ' . $attributes['class'] . '"' . $attributes . '>';
  *  // Produces <cat class="cat black-cat white-cat black-white-cat" id="socks">
  * @endcode
  */
@@ -64,6 +63,18 @@ public function offsetGet($name) {
    * Implements ArrayAccess::offsetSet().
    */
   public function offsetSet($name, $value) {
+    $this->storage[$name] = $this->createAttributeValue($name, $value);
+  }
+
+/**
+ * Creates the different types of attribute values.
+ * @param string $name
+ *   The attribute name.
+ * @param mixed $value
+ *   The attribute value.
+ * @return object
+ */
+  protected function createAttributeValue($name, $value) {
     if (is_array($value)) {
       $value = new AttributeArray($name, $value);
     }
@@ -73,13 +84,7 @@ public function offsetSet($name, $value) {
     elseif (!is_object($value)) {
       $value = new AttributeString($name, $value);
     }
-    // The $name could be NULL.
-    if (isset($name)) {
-      $this->storage[$name] = $value;
-    }
-    else {
-      $this->storage[] = $value;
-    }
+    return $value;
   }
 
   /**
@@ -103,9 +108,9 @@ public function __toString() {
     $return = '';
     foreach ($this->storage as $name => $value) {
       if (!$value->printed()) {
-        $rendered = is_object($value) ? $value->render() : (check_plain($name) . ' = "' . check_plain($value) . '"');
+        $rendered = $value->render();
         if ($rendered) {
-          $return .= " $rendered";
+          $return .= ' ' . $rendered;
         }
       }
     }
@@ -117,9 +122,7 @@ public function __toString() {
    */
   public function  __clone() {
     foreach ($this->storage as $name => $value) {
-      if (is_object($value)) {
-        $this->storage[$name] = clone $value;
-      }
+      $this->storage[$name] = clone $value;
     }
   }
 
@@ -129,12 +132,4 @@ public function  __clone() {
   public function getIterator() {
     return new \ArrayIterator($this->storage);
   }
-
-  /**
-   * Returns the whole array.
-   */
-  public function value() {
-    return $this->value;
-  }
-
 }
diff --git a/core/lib/Drupal/Core/Template/AttributeArray.php b/core/lib/Drupal/Core/Template/AttributeArray.php
index d3521e0..a4d1d12 100644
--- a/core/lib/Drupal/Core/Template/AttributeArray.php
+++ b/core/lib/Drupal/Core/Template/AttributeArray.php
@@ -14,13 +14,13 @@
  * To use with Attribute, the array must be specified.
  * Correct:
  * @code
- *  $attributes = new Attribute(array());
+ *  $attributes = new Attribute();
  *  $attributes['class'] = array();
  *  $attributes['class'][] = 'cat';
  * @endcode
  * Incorrect:
  * @code
- *  $attributes = new Attribute(array());
+ *  $attributes = new Attribute();
  *  $attributes['class'][] = 'cat';
  * @endcode
  *
@@ -66,7 +66,7 @@ public function offsetExists($offset) {
    */
   public function __toString() {
     $this->printed = TRUE;
-    return implode(' ', array_map('check_plain', $this->value));
+    return check_plain(implode(' ', $this->value));
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Template/AttributeBoolean.php b/core/lib/Drupal/Core/Template/AttributeBoolean.php
index 48ca388..7bfc527 100644
--- a/core/lib/Drupal/Core/Template/AttributeBoolean.php
+++ b/core/lib/Drupal/Core/Template/AttributeBoolean.php
@@ -16,12 +16,12 @@
  *
  * To set a boolean attribute on the Attribute class, set it to TRUE.
  * @code
- *  $attributes = new Attribute(array());
+ *  $attributes = new Attribute();
  *  $attributes['disabled'] = TRUE;
- *  echo '<select ' . $attributes . '/>';
+ *  echo '<select' . $attributes . '/>';
  *  // produces <select disabled>;
  *  $attributes['disabled'] = FALSE;
- *  echo '<select ' . $attributes . '/>';
+ *  echo '<select' . $attributes . '/>';
  *  // produces <select>;
  * @endcode
  *
diff --git a/core/lib/Drupal/Core/Template/AttributeValueBase.php b/core/lib/Drupal/Core/Template/AttributeValueBase.php
index df187df..39177a2 100644
--- a/core/lib/Drupal/Core/Template/AttributeValueBase.php
+++ b/core/lib/Drupal/Core/Template/AttributeValueBase.php
@@ -53,7 +53,7 @@ public function __construct($name, $value) {
    *   The string representation of the attribute.
    */
   public function render() {
-    return $this->name . '="' . $this . '"';
+    return check_plain($this->name) . '="' . $this . '"';
   }
 
   /**
diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/AttributesUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/AttributesUnitTest.php
index 7b5305d..c28f675 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Common/AttributesUnitTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Common/AttributesUnitTest.php
@@ -27,6 +27,7 @@ public static function getInfo() {
    */
   function testDrupalAttributes() {
     // Verify that special characters are HTML encoded.
+    $this->assertIdentical((string) new Attribute(array('&"\'<>' => 'value')), ' &amp;&quot;&#039;&lt;&gt;="value"', 'HTML encode attribute names.');
     $this->assertIdentical((string) new Attribute(array('title' => '&"\'<>')), ' title="&amp;&quot;&#039;&lt;&gt;"', 'HTML encode attribute values.');
 
     // Verify multi-value attributes are concatenated with spaces.
@@ -37,6 +38,10 @@ function testDrupalAttributes() {
     $this->assertIdentical((string) new Attribute(array('alt' => '')), ' alt=""', 'Empty attribute value #1.');
     $this->assertIdentical((string) new Attribute(array('alt' => NULL)), ' alt=""', 'Empty attribute value #2.');
 
+    // Verify boolean attribute values are rendered correctly.
+    $this->assertIdentical((string) new Attribute(array('disabled' => TRUE)), ' disabled', 'Boolean attribute is rendered.');
+    $this->assertIdentical((string) new Attribute(array('disabled' => FALSE)), '', 'Boolean attribute is not rendered.');
+
     // Verify multiple attributes are rendered.
     $attributes = array(
       'id' => 'id-test',
