summaryrefslogtreecommitdiff
path: root/modules/taxonomy
diff options
context:
space:
mode:
authorwebchick <webchick@24967.no-reply.drupal.org>2012-03-13 09:46:37 -0700
committerwebchick <webchick@24967.no-reply.drupal.org>2012-03-13 09:46:37 -0700
commit597bfd529759dcc1fdf9760c6917c867f09f60b5 (patch)
treea26eb653287172b4218ac8c379d18ca162e31e03 /modules/taxonomy
parent1569c4bde2de6097de2abd6f5f66d62f0cede3c5 (diff)
downloadbrdo-597bfd529759dcc1fdf9760c6917c867f09f60b5.tar.gz
brdo-597bfd529759dcc1fdf9760c6917c867f09f60b5.tar.bz2
Issue #93854 by pillarsdotnet, Steven Jones, Dave Reid, ericduran, xjm, das-peter, e2thex, axel.rutz, mstrelan, mikestefff | moonray: Fixed Allow autocompletion requests to include slashes.
Diffstat (limited to 'modules/taxonomy')
-rw-r--r--modules/taxonomy/taxonomy.pages.inc7
-rw-r--r--modules/taxonomy/taxonomy.test52
2 files changed, 59 insertions, 0 deletions
diff --git a/modules/taxonomy/taxonomy.pages.inc b/modules/taxonomy/taxonomy.pages.inc
index 3714ca3b0..501ebbe10 100644
--- a/modules/taxonomy/taxonomy.pages.inc
+++ b/modules/taxonomy/taxonomy.pages.inc
@@ -108,6 +108,13 @@ function taxonomy_term_feed($term) {
* @see taxonomy_field_widget_info()
*/
function taxonomy_autocomplete($field_name, $tags_typed = '') {
+ // If the request has a '/' in the search text, then the menu system will have
+ // split it into multiple arguments, recover the intended $tags_typed.
+ $args = func_get_args();
+ // Shift off the $field_name argument.
+ array_shift($args);
+ $tags_typed = implode('/', $args);
+
// Make sure the field exists and is a taxonomy field.
if (!($field = field_info_field($field_name)) || $field['type'] !== 'taxonomy_term_reference') {
// Error string. The JavaScript handler will realize this is not JSON and
diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test
index b99db8ee2..461f27732 100644
--- a/modules/taxonomy/taxonomy.test
+++ b/modules/taxonomy/taxonomy.test
@@ -706,6 +706,58 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
}
/**
+ * Tests term autocompletion edge cases with slashes in the names.
+ */
+ function testTermAutocompletion() {
+ // Add a term with a slash in the name.
+ $first_term = $this->createTerm($this->vocabulary);
+ $first_term->name = '10/16/2011';
+ taxonomy_term_save($first_term);
+ // Add another term that differs after the slash character.
+ $second_term = $this->createTerm($this->vocabulary);
+ $second_term->name = '10/17/2011';
+ taxonomy_term_save($second_term);
+ // Add another term that has both a comma and a slash character.
+ $third_term = $this->createTerm($this->vocabulary);
+ $third_term->name = 'term with, a comma and / a slash';
+ taxonomy_term_save($third_term);
+
+ // Try to autocomplete a term name that matches both terms.
+ // We should get both term in a json encoded string.
+ $input = '10/';
+ $path = 'taxonomy/autocomplete/taxonomy_';
+ $path .= $this->vocabulary->machine_name . '/' . $input;
+ // The result order is not guaranteed, so check each term separately.
+ $url = url($path, array('absolute' => TRUE));
+ $result = drupal_http_request($url);
+ $data = drupal_json_decode($result->data);
+ $this->assertEqual($data[$first_term->name], check_plain($first_term->name), 'Autocomplete returned the first matching term');
+ $this->assertEqual($data[$second_term->name], check_plain($second_term->name), 'Autocomplete returned the second matching term');
+
+ // Try to autocomplete a term name that matches first term.
+ // We should only get the first term in a json encoded string.
+ $input = '10/16';
+ $url = 'taxonomy/autocomplete/taxonomy_';
+ $url .= $this->vocabulary->machine_name . '/' . $input;
+ $this->drupalGet($url);
+ $target = array($first_term->name => check_plain($first_term->name));
+ $this->assertRaw(drupal_json_encode($target), 'Autocomplete returns only the expected matching term.');
+
+ // Try to autocomplete a term name with both a comma and a slash.
+ $input = '"term with, comma and / a';
+ $url = 'taxonomy/autocomplete/taxonomy_';
+ $url .= $this->vocabulary->machine_name . '/' . $input;
+ $this->drupalGet($url);
+ $n = $third_term->name;
+ // Term names containing commas or quotes must be wrapped in quotes.
+ if (strpos($third_term->name, ',') !== FALSE || strpos($third_term->name, '"') !== FALSE) {
+ $n = '"' . str_replace('"', '""', $third_term->name) . '"';
+ }
+ $target = array($n => check_plain($third_term->name));
+ $this->assertRaw(drupal_json_encode($target), 'Autocomplete returns a term containing a comma and a slash.');
+ }
+
+ /**
* Save, edit and delete a term using the user interface.
*/
function testTermInterface() {