From e2743fdb8957ad05b995412242f86d2e4ad1d7b0 Mon Sep 17 00:00:00 2001 From: catch Date: Mon, 24 Sep 2012 10:33:31 +0100 Subject: [PATCH] Issue #1575060 by andypost, mcjim, nod_: Fixed ajax_html_ids() are broken for forms with file element (encoding=multipart/form-data). --- core/includes/common.inc | 3 ++- core/misc/ajax.js | 11 +++++++---- .../simpletest/lib/Drupal/simpletest/WebTestBase.php | 7 +++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/core/includes/common.inc b/core/includes/common.inc index e7ebd1f4cdd..e8ae4786cda 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3528,7 +3528,8 @@ function drupal_html_id($id) { // requested id. $_POST['ajax_html_ids'] contains the ids as they were // returned by this function, potentially with the appended counter, so // we parse that to reconstruct the $seen_ids array. - foreach ($_POST['ajax_html_ids'] as $seen_id) { + $ajax_html_ids = explode(' ', $_POST['ajax_html_ids']); + foreach ($ajax_html_ids as $seen_id) { // We rely on '--' being used solely for separating a base id from the // counter, which this function ensures when returning an id. $parts = explode('--', $seen_id, 2); diff --git a/core/misc/ajax.js b/core/misc/ajax.js index 94bfb890fb5..8e935ed266d 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -284,10 +284,13 @@ Drupal.ajax.prototype.beforeSerialize = function (element, options) { // Prevent duplicate HTML ids in the returned markup. // @see drupal_html_id() - options.data['ajax_html_ids[]'] = []; - $('[id]').each(function () { - options.data['ajax_html_ids[]'].push(this.id); - }); + var ids = document.querySelectorAll('[id]'); + var ajaxHtmlIds = []; + for (var i = 0, il = ids.length; i < il; i++) { + ajaxHtmlIds.push(ids[i].id); + } + // Join IDs to minimize request size. + options.data.ajax_html_ids = ajaxHtmlIds.join(' '); // Allow Drupal to return new JavaScript and CSS files to load without // returning the ones already loaded. diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 385d6f4586a..cc54b6739f4 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -1284,9 +1284,12 @@ abstract class WebTestBase extends TestBase { $extra_post .= '&' . urlencode($key) . '=' . urlencode($value); } } + $ajax_html_ids = array(); foreach ($this->xpath('//*[@id]') as $element) { - $id = (string) $element['id']; - $extra_post .= '&' . urlencode('ajax_html_ids[]') . '=' . urlencode($id); + $ajax_html_ids[] = (string) $element['id']; + } + if (!empty($ajax_html_ids)) { + $extra_post .= '&' . urlencode('ajax_html_ids') . '=' . urlencode(implode(' ', $ajax_html_ids)); } if (isset($drupal_settings['ajaxPageState'])) { $extra_post .= '&' . urlencode('ajax_page_state[theme]') . '=' . urlencode($drupal_settings['ajaxPageState']['theme']);