-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdrupal7-60-core.patch
91 lines (87 loc) · 4.26 KB
/
drupal7-60-core.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
diff --git a/includes/common.inc b/includes/common.inc
index 3be653ab..39587a8f 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -3999,53 +3999,26 @@ function drupal_html_id($id) {
}
$seen_ids_init = &$drupal_static_fast['seen_ids_init'];
if (!isset($seen_ids_init)) {
- // Ideally, Drupal would provide an API to persist state information about
- // prior page requests in the database, and we'd be able to add this
- // function's $seen_ids static variable to that state information in order
- // to have it properly initialized for this page request. However, no such
- // page state API exists, so instead, ajax.js adds all of the in-use HTML
- // IDs to the POST data of Ajax submissions. Direct use of $_POST is
- // normally not recommended as it could open up security risks, but because
- // the raw POST data is cast to a number before being returned by this
- // function, this usage is safe.
- if (empty($_POST['ajax_html_ids'])) {
- $seen_ids_init = array();
+ // A number of contrib modules were relying on being able to unset
+ // $_POST['ajax_html_ids'] to not trigger the unique ID functionality
+ // on AJAX requests, so we still check that variable and respond as they
+ // would expect.
+ if (empty($_POST['ajax_html_ids']) || empty($_POST['ajax_html_ids_counter'])) {
+ $seen_ids_init = 1;
}
else {
- // This function ensures uniqueness by appending a counter to the base id
- // requested by the calling function after the first occurrence of that
- // 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.
- if (isset($_POST['ajax_html_ids'][0]) && strpos($_POST['ajax_html_ids'][0], ',') === FALSE) {
- $ajax_html_ids = $_POST['ajax_html_ids'];
+ if (is_numeric($_POST['ajax_html_ids_counter'])) {
+ $seen_ids_init = $_POST['ajax_html_ids_counter'];
}
else {
- // jquery.form.js may send the server a comma-separated string as the
- // first element of an array (see http://drupal.org/node/1575060), so
- // we need to convert it to an array in that case.
- $ajax_html_ids = explode(',', $_POST['ajax_html_ids'][0]);
- }
- 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);
- if (!empty($parts[1]) && is_numeric($parts[1])) {
- list($seen_id, $i) = $parts;
- }
- else {
- $i = 1;
- }
- if (!isset($seen_ids_init[$seen_id]) || ($i > $seen_ids_init[$seen_id])) {
- $seen_ids_init[$seen_id] = $i;
- }
+ $seen_ids_init = 1;
}
}
}
if (!isset($drupal_static_fast['seen_ids'])) {
$drupal_static_fast['seen_ids'] = &drupal_static(__FUNCTION__, $seen_ids_init);
}
- $seen_ids = &$drupal_static_fast['seen_ids'];
+ $seen_ids = &drupal_static(__FUNCTION__, array());
$id = strtr(drupal_strtolower($id), array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
diff --git a/misc/ajax.js b/misc/ajax.js
index dd06575d..f4a2e555 100644
--- a/misc/ajax.js
+++ b/misc/ajax.js
@@ -320,9 +320,16 @@ Drupal.ajax.prototype.beforeSerialize = function (element, options) {
// Prevent duplicate HTML ids in the returned markup.
// @see drupal_html_id()
- options.data['ajax_html_ids[]'] = [];
+ options.data['ajax_html_ids[]'] = 1;
+ options.data['ajax_html_ids_counter'] = 1;
$('[id]').each(function () {
- options.data['ajax_html_ids[]'].push(this.id);
+ // If this ID already has a counter, then ensure that the counter is at least that.
+ if (this.id.indexOf('--') != -1) {
+ var potentialCounter = this.id.substring(this.id.indexOf('--') + 2);
+ if ((typeof potentialCounter === 'number' || typeof potentialCounter === 'string') && potentialCounter !== '' && !isNaN(potentialCounter)) {
+ options.data['ajax_html_ids_counter'] = Math.max(options.data['ajax_html_ids_counter'], potentialCounter);
+ }
+ }
});
// Allow Drupal to return new JavaScript and CSS files to load without