Download & Extend

taxonomy_save_term should trim term upon save

Project:Drupal core
Version:7.x-dev
Component:taxonomy.module
Category:bug report
Priority:normal
Assigned:roychri
Status:closed (fixed)

Issue Summary

Reproduce: Save title that has a space at end.

Problem: Nat does not strip spaces out of the node title when it adds the term to the term_data table.

This causes a problem with taxonomy_get_term_by_name() taking the title from the arg(), or anywhere else where Drupal has already stripped the space from the title.

Proposed solution: Add PHP trim to NAT module (Patch) prior to data
getting added to DB.

AttachmentSizeStatusTest resultOperations
trimtitle.patch603 bytesIgnored: Check issue status.NoneNone

Comments

#1

Status:active» needs work

I assume that you are using pgSQL? This shouldn't really be a problem with MySQL (untested) as varchar fields are automatically trimmed.

re: patch - could you please move the trim to _nat_update_terms? Also, when you submit a patch, please set the status to "code needs review".

Cheers,
-K

#2

I'm using MySQL 5.038
Thanks for the tip on submitting.
New version uploaded.

AttachmentSizeStatusTest resultOperations
trimtitle2.patch10.22 KBIgnored: Check issue status.NoneNone

#3

I'm more of a themer than a developer, so I don't really know why the title varchar is not geting stripped in mySQL 5, for me, but this patch seems to fix the problem described, fo me.

If I have made any mistakes in my second patch, please let me know.

Thanks!
arcX

#4

Status:needs work» active

Hello Alex,

Apologies for the delay.

a) MySQL varchar fields preserve trailing whitespace from v5 onwards.
b) The same issue also applies to the taxonomy module in general. Adding a term via the taxonomy UI with trailing whitespace will result in the same issue.
c) Fixing point b will involve adding the trims to taxonomy_save_term which is what the NAT module calls eventually.

Therefore, it will be best if you take this issue to the core queue and provide a patch for taxonomy_save_term. This issue might actually prove to be a lot more widespread than just the taxonomy module though, and should probably be fixed in the forms API.

Not sure how applicable this is for D6 though.

Patch: Incidentally, your last patch had a lot of other changes mixed in it. Also, when you submit a patch, please be sure to set it to "Patch (Code needs review)".

Leaving issue open.

-K

#5

Title:Nat does not strip spaces out of the node title when it adds the term to the term_data table» taxonomy_save_term should trim term upon save
Project:Node Auto Term [NAT]» Drupal core
Version:master» 6.x-dev
Component:Code» taxonomy.module

Moving to Drupal queue.

#6

Status:active» needs review

New patch trims terms in taxonomy_save_term as suggested by Zen

AttachmentSizeStatusTest resultOperations
taxonomy-trim.patch946 bytesIgnored: Check issue status.NoneNone

#7

Version:6.x-dev» 7.x-dev

#8

The patch above needs reworking as it fails when applied to the latest CVS snapshot of Drupal 7.x.

#9

Status:needs review» needs work

Oops.

#10

Assigned to:Anonymous» roychri

I'll work on this.

#11

Status:needs work» needs review

Here's a re-rolled patch. I have tested it against free tagging and confirmed it fixed the bug.

AttachmentSizeStatusTest resultOperations
taxonomy-trim.patch695 bytesIgnored: Check issue status.NoneNone

#12

Status:needs review» needs work

Tested patch and it works, but there's a minor coding standard violation. Need a space after the if and before the {. :)

#13

Status:needs work» needs review

Here's the new version with the correct format to comply to the coding standards.

AttachmentSizeStatusTest resultOperations
taxonomy-trim.patch770 bytesIgnored: Check issue status.NoneNone

#14

Status:needs review» reviewed & tested by the community

Hi,
I've applied this patch to the dev tarbal of Drupal 7.x and it works!!!

#15

Status:reviewed & tested by the community» needs review

Still applies with offset. Seems like a good change to me. However there's an issue elsewhere for trimming usernames in the login form, so I'm marking back to review to see if we need to do this more generally.

#16

While we are on the subject, you can also save a vocabulary with a space in it. Let's fix this in the same run ? (I can imagine a use case for views having trouble with it, unless views trims it)

#17

Re-rolled including vocabulary names, and although it's clear what's going on, some comments.

AttachmentSizeStatusTest resultOperations
trim_term_vocab.patch1.42 KBIgnored: Check issue status.NoneNone

#18

Re-rolled to deal with taxonomy API changes.

To summarize, this patch trims whitespace from taxonomy terms and vocabulary names.

AttachmentSizeStatusTest resultOperations
trim_taxonomy.patch1.23 KBIgnored: Check issue status.NoneNone

#19

Status:needs review» fixed

Committed to CVS HEAD. Thanks.

--project followup subject--

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

#20

Status:fixed» closed (fixed)

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