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.

Comments

Zen’s picture

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

alexiscott’s picture

StatusFileSize
new10.22 KB

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

alexiscott’s picture

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

Zen’s picture

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

Zen’s picture

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.

jody lynn’s picture

Status: Active » Needs review
StatusFileSize
new946 bytes

New patch trims terms in taxonomy_save_term as suggested by Zen

jody lynn’s picture

Version: 6.x-dev » 7.x-dev
Anonymous’s picture

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

Anonymous’s picture

Status: Needs review » Needs work

Oops.

roychri’s picture

Assigned: Unassigned » roychri

I'll work on this.

roychri’s picture

Status: Needs work » Needs review
StatusFileSize
new695 bytes

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

webchick’s picture

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 {. :)

roychri’s picture

Status: Needs work » Needs review
StatusFileSize
new770 bytes

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

gonzgonz’s picture

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!!!

catch’s picture

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.

swentel’s picture

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)

catch’s picture

StatusFileSize
new1.42 KB

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

jody lynn’s picture

StatusFileSize
new1.23 KB

Re-rolled to deal with taxonomy API changes.

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

dries’s picture

Status: Needs review » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)

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