SQL in taxonomy_get_term_by_name() should use =, not LIKE

Heine - October 3, 2007 - 22:44
Project:Drupal
Version:5.x-dev
Component:taxonomy.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

Reported by John Morahan

Drupal 5.2 taxonomy.module

If a user uses free tagging to add a '%' symbol as a tag, it is
impossible for anyone to add any further tags as they all get changed to
'%'.

This is because taxonomy_get_term_by_name() does a 'LIKE' match instead
of '='.

Someone with 'administer taxonomy' permission can manually delete the
offending term, fixing the problem until it gets added again.

Related issue (6.x): http://drupal.org/node/165160

To reproduce:

1. create a free tagging vocabulary, assign to a node type
2. create a node of that type, add % as a tag
3. edit the node, or create a new node of that type, add different tags,
and save again
4. observe that % was saved as a tag, and any other tags were not

#1

wmostrey - December 7, 2007 - 19:53
Version:5.2» 5.4

This still applies, and this can also be tested on groups.drupal.org. For instance if you try to enter "3rd party software" as a tag, it will get replaced with "3%" since it appears someone added that as a tag already. This is not a critical issue but really should be fixed because it interferes with the user experience and is experienced as a bug (which it is).

#2

wmostrey - December 7, 2007 - 19:53
Version:5.4» 5.5

#3

John Morahan - December 9, 2007 - 11:24
Status:active» patch (code needs review)
AttachmentSize
taxonomy_get_term_by_name-like.patch914 bytes

#4

Rowanw - December 29, 2007 - 03:09

Applied the patch and followed the steps above, no problems.

#5

wmostrey - December 29, 2007 - 17:12
Status:patch (code needs review)» patch (reviewed & tested by the community)

Applies cleanly and works as advertised.

#6

Arancaytar - February 12, 2008 - 17:20
Version:5.5» 6.x-dev
Status:patch (reviewed & tested by the community)» patch (code needs work)

This issue still exists in D6.

#7

John Morahan - March 16, 2008 - 19:30
Status:patch (code needs work)» patch (code needs review)

Well, in D6 the order was reversed, so it's not exactly the same issue: it's now impossible to add a tag with % in it, if the pattern matches an existing tag. Still a problem though.

AttachmentSize
taxonomy_get_term_by_name-like.patch671 bytes

#8

Arancaytar - June 9, 2008 - 12:42
Status:patch (code needs review)» patch (reviewed & tested by the community)

This bug and corresponding patch still apply. Please do not forget to backport this to D5.

#9

Arancaytar - June 9, 2008 - 12:43
Title:% as a free tag prevents further tag addition.» SQL in taxonomy_get_term_by_name() should use =, not LIKE

Clarified title.

#10

Gábor Hojtsy - June 25, 2008 - 08:05
Version:6.x-dev» 7.x-dev

Thanks, committed. Should also be fixed in Drupal 5 and Drupal 7. Putting to Drupal 7 first, because it has the same code (presumably), so it should be easy to commit there and then set back for Drupal 5.

#11

Dries - June 28, 2008 - 19:51
Version:7.x-dev» 5.x-dev

Committed this to CVS HEAD. Thanks John. Changing version.

#12

drumm - July 6, 2008 - 00:50
Status:patch (reviewed & tested by the community)» fixed

Committed to 5.x

#13

gchan - July 12, 2008 - 00:01

To get better performance, may want to use strtolower first instead of inside the SQL:

$db_result = db_query(db_rewrite_sql("SELECT t.tid, t.* FROM {term_data} t WHERE LOWER(t.name) = '%s' ", 't', 'tid'), strtolower(trim($name)));

#14

Anonymous (not verified) - July 31, 2008 - 04:46
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.