From 15cd0ca6ff82a49e2f7277c6372e8e2dd645b5eb Mon Sep 17 00:00:00 2001 From: webchick Date: Wed, 29 Feb 2012 00:15:01 -0800 Subject: =?UTF-8?q?Issue=20#814804=20by=20JacobSingh,=20ksenzee,=20xjm,=20?= =?UTF-8?q?draenen,=20paul.lovvik,=20David=5FRothstein,=20G=C3=A1bor=20Hoj?= =?UTF-8?q?tsy,=20Yorirou:=20Fixed=20taxonomy=5Fautocomplete()=20produces?= =?UTF-8?q?=20SQL=20error=20for=20nonexistent=20field.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/taxonomy/taxonomy.pages.inc | 8 +++++++- modules/taxonomy/taxonomy.test | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'modules/taxonomy') diff --git a/modules/taxonomy/taxonomy.pages.inc b/modules/taxonomy/taxonomy.pages.inc index 26304136d..3714ca3b0 100644 --- a/modules/taxonomy/taxonomy.pages.inc +++ b/modules/taxonomy/taxonomy.pages.inc @@ -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); diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test index 70b2e8e12..98f44000e 100644 --- a/modules/taxonomy/taxonomy.test +++ b/modules/taxonomy/taxonomy.test @@ -696,6 +696,14 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { $input = substr($term_objects['term3']->name, 0, 3); $this->drupalGet('taxonomy/autocomplete/taxonomy_' . $this->vocabulary->machine_name . '/' . $input); $this->assertRaw('{"' . $term_objects['term3']->name . '":"' . $term_objects['term3']->name . '"}', t('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term3']->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.')); } /** -- cgit v1.2.3