diff options
author | Alex Pott <alex.a.pott@googlemail.com> | 2025-04-16 13:23:42 +0200 |
---|---|---|
committer | Alex Pott <alex.a.pott@googlemail.com> | 2025-04-16 14:56:40 +0200 |
commit | 4fd6234027ca5778932266852376afbc8cea2b4c (patch) | |
tree | 01009c804cf33000873489f656aa29998e2205fd /core | |
parent | a551f2b2feac369df92ef7f8888c7fef309a8700 (diff) | |
download | drupal-4fd6234027ca5778932266852376afbc8cea2b4c.tar.gz drupal-4fd6234027ca5778932266852376afbc8cea2b4c.zip |
Issue #3513307 by bigbabert, smustgrave, nicxvan, quietone, ghost of drupal past: Use xpath instead of preg_match to search html string in BrowserTestBase
Diffstat (limited to 'core')
-rw-r--r-- | core/tests/Drupal/Tests/BrowserTestBase.php | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 457e22286f4..12228dbea72 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -609,9 +609,8 @@ abstract class BrowserTestBase extends TestCase { * The JSON decoded drupalSettings value from the current page. */ protected function getDrupalSettings() { - $html = $this->getSession()->getPage()->getContent(); - if (preg_match('@<script type="application/json" data-drupal-selector="drupal-settings-json">([^<]*)</script>@', $html, $matches)) { - $settings = Json::decode($matches[1]); + if ($elements = $this->xpath('//script[@type="application/json" and @data-drupal-selector="drupal-settings-json"]')) { + $settings = Json::decode($elements[0]->getText()); if (isset($settings['ajaxPageState']['libraries'])) { $settings['ajaxPageState']['libraries'] = UrlHelper::uncompressQueryParameter($settings['ajaxPageState']['libraries']); } |