TryGhost / Ghost

Independent technology for modern publishing, memberships, subscriptions and newsletters.
https://ghost.org
MIT License
47.55k stars 10.38k forks source link

Tag replacement not working #1402

Closed matthojo closed 9 years ago

matthojo commented 11 years ago

From the forum: https://ghost.org/forum/bugs-suggestions/2411-editing-the-character-case-of-tags/

How to reproduce this bug

  1. Create a new post with a tag of "example"
  2. Publish this post
  3. Edit this post by removing our "example" tag and adding "EXAMPLE" in its place
  4. Reload the blog page to see that neither the "example" nor "EXAMPLE" tags exist on your post.
  5. Edit the post once again to add back in our "EXAMPLE" tag which shouldn't have been removed.
  6. Reload the blog page to see that now both "example" and "EXAMPLE" exist on the page.
  7. Remove the "example" tag to fix the issue.

I initially published it with a lowercase "css", after noticing that this didn't look good I edited my post to remove the "css" tag and add in a new "CSS" tag. Upon clicking save neither of the tags had been added. When editing the post for a second time to once again add the "CSS" tag, both the "css" and "CSS" tags ended up being added to the post. Afterwards I was able to remove the "css" tag but keep the "CSS" tag.

gotjosh commented 11 years ago

I tried to reproduce this issue with the current master, and I can't reproduce it. Could you please specify the Ghost version you're using?

ErisDS commented 11 years ago

This bug was reported with MySQL - did you try to reproduce with MySQL?

gotjosh commented 11 years ago

@ErisDS Confirmed. I reproduced it using MySQL.

halfdan commented 11 years ago

This is probably an issue with case sensitivity: SQLite3 is case sensitive by default while for MySQL it depends on the collation (but usually it's case insensitive).

mysql> select slug from tags where name = 'example';
+-----------+
| slug      |
+-----------+
| example   |
| example-2 |
+-----------+

vs.

sqlite> select slug from tags where name = "example";
example
gotjosh commented 11 years ago

@halfdan You're totally right, thank you for the explanation.

gotjosh commented 11 years ago

@ErisDS @halfdan by setting the collation to utf8_bin with t.collate('utf8_bin'); on the https://github.com/TryGhost/Ghost/blob/master/core/server/data/migration/000.js#L99 it works as intented the only problem is that t.collate only works with mysql so the adapter will have to be validated.

Is this something we need to include inside the migration, or we let the users know so that they can properly set it in their MySQL installation?

halfdan commented 11 years ago

I think this should be handled by bookshelf.js/knex.js - maybe @tgriesser can have a look at this. From my Rails/ActiveRecord experience I know that AR has an option to allow case-sensitive or case-insensitive matches which automatically adjusts the queries for each database.

See: http://edgeguides.rubyonrails.org/active_record_validations.html#uniqueness

halfdan commented 10 years ago

@tgriesser Is there any way in bookshelf to execute case insensitive queries?

jaswilli commented 9 years ago

Going to close as this is way out of date. The tag management page should be a workaround for any issues like this, and if there are still issues surrounding this behavior they should be re-raised and documented.

chancesmith commented 9 years ago

I'm still having trouble with this. When I type in either cased tag, both show up after I save.

I'll do a screencast if needed. I don't mind if it will help.

I have /tags/tldr/ & /tags/tldr-2/. On my post it shows both tag: https://www.dropbox.com/s/x39xsi9lnk6jt0t/Screenshot%202015-01-12%2002.08.54.png?dl=0

ErisDS commented 9 years ago

@chancesmith That's because they are, essentially, both the same tag. In the next version of Ghost there will be a new interface where you can edit your tags to fix this problem.