From e71fcde4d2c526374c91975d524796adbea5632a Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Sun, 6 Feb 2022 14:28:45 +0000
Subject: [PATCH] Issue #3172166 by Pooja Ganjage, ekes, Megha_kundar, xjm,
 alexpott, tstoeckler, mbovan, Spokje: Element::properties() produces notices
 if given an array with integer keys

(cherry picked from commit e14d16c5894b8ca476ca9fb2de86d7b4625a4f14)
---
 core/lib/Drupal/Core/Render/Element.php             | 2 +-
 core/tests/Drupal/Tests/Core/Render/ElementTest.php | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/core/lib/Drupal/Core/Render/Element.php b/core/lib/Drupal/Core/Render/Element.php
index dfd4eb099d36..75c3ab740174 100644
--- a/core/lib/Drupal/Core/Render/Element.php
+++ b/core/lib/Drupal/Core/Render/Element.php
@@ -24,7 +24,7 @@ class Element {
    *   TRUE of the key is a property, FALSE otherwise.
    */
   public static function property($key) {
-    return $key[0] == '#';
+    return is_string($key) && $key[0] == '#';
   }
 
   /**
diff --git a/core/tests/Drupal/Tests/Core/Render/ElementTest.php b/core/tests/Drupal/Tests/Core/Render/ElementTest.php
index a09cb3f61feb..1c795c7dba0b 100644
--- a/core/tests/Drupal/Tests/Core/Render/ElementTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/ElementTest.php
@@ -19,6 +19,7 @@ public function testProperty() {
     $this->assertTrue(Element::property('#property'));
     $this->assertFalse(Element::property('property'));
     $this->assertFalse(Element::property('property#'));
+    $this->assertFalse(Element::property(0));
   }
 
   /**
@@ -29,13 +30,12 @@ public function testProperties() {
       '#property1' => 'property1',
       '#property2' => 'property2',
       'property3' => 'property3',
+      0 => [],
     ];
 
     $properties = Element::properties($element);
 
-    $this->assertContains('#property1', $properties);
-    $this->assertContains('#property2', $properties);
-    $this->assertNotContains('property3', $properties);
+    $this->assertSame(['#property1', '#property2'], $properties);
   }
 
   /**
-- 
GitLab