Commit ed9a5d96 authored by catch's avatar catch
Browse files

Issue #814804 by JacobSingh, ksenzee, draenen, et al: Fixed...

Issue #814804 by JacobSingh, ksenzee, draenen, et al: Fixed taxonomy_autocomplete() produces SQL error for nonexistent field.
parent 1ab8af6d
......@@ -108,7 +108,13 @@ function taxonomy_term_feed($term) {
* @see taxonomy_field_widget_info()
*/
function taxonomy_autocomplete($field_name, $tags_typed = '') {
$field = field_info_field($field_name);
// 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
// will display it as debugging information.
print t('Taxonomy field @field_name not found.', array('@field_name' => $field_name));
exit;
}
// The user enters a comma-separated list of tags. We only autocomplete the last tag.
$tags_typed = drupal_explode_tags($tags_typed);
......
......@@ -706,6 +706,14 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
$input = substr($term_objects['term4']->name, 0, 3);
$this->drupalGet('taxonomy/autocomplete/taxonomy_' . $this->vocabulary->machine_name . '/' . $input);
$this->assertRaw('{"' . $term_objects['term4']->name . '":"' . $term_objects['term4']->name . '"}', t('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term4']->name)));
// Test taxonomy autocomplete with a nonexistent field.
$field_name = $this->randomName();
$tag = $this->randomName();
$message = t("Taxonomy field @field_name not found.", array('@field_name' => $field_name));
$this->assertFalse(field_info_field($field_name), t('Field %field_name does not exist.', array('%field_name' => $field_name)));
$this->drupalGet('taxonomy/autocomplete/' . $field_name . '/' . $tag);
$this->assertRaw($message, t('Autocomplete returns correct error message when the taxonomy field does not exist.'));
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment