Match tag names case-insensitively #776
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
True (user) story
When I add a link from mobile with a tag, the keyboard will automatically capitalize the first letter of the tag I am adding. My expectation was that the system would recognize the preexisting tag but, instead, an entirely new tag was added and I now have both
book
andBook
in existence.As a link adder, I want the system to recognize a preexisting tag despite case differences such that I do not have to fiddle with the keyboard autocapitalize. (I've looked into disabling that behavior before for another project, but found no reliable way to mark the input field for mobile web browsers.)
So that is my side of the story; now, whether you want to also incorporate this change upstream depends. If anyone is relying on case differences to work correctly, this will break their ability to add links to one of the tags: the database will match one of them first and that will be the one assigned to the link, losing the ability to assign to the other one. It would not be my expectation, though, that someone is maintaining both
Name
andname
and carefully adding some links to one but not the other.I fully understand if you do not like the change and don't want to merge it, no hard feelings; I could have discussed it first but it was a small change and a good excuse to mess with Podman containers :)
Compatibility
While searching for prior discussion, I noticed you wrote this:
Agree, that's ugly and should be avoided if possible. I've verified that the SQL function is supported by all databases mentioned in the LinkAce setup documentation, including the databases that are marked as "untested, might work":
Listed as uppercase
LOWER()
, but tested to work lowercase as wellI've run the test suite on the default database which I'm pretty sure is MariaDB, and the change runs on my own setup which uses SQLite. In the latter, I have been adding test links and doing things like removing the tag first or reassigning all links from it first, trying to create a duplicate tag name from the
/tags/create
page itself, clearing them from trash, etc., and it all works correctly.Implementation
The first bit of the new function checks if we are looking for a record with a specific
name
. If so, it will search for it by lowercasing both the existing database records and the name being searched for. They both use the SQLlower()
function, rather than usingstrtolower()
on the search value, to avoid any discrepancies there.If this does not return a result, or we were not doing a name search, the rest of the implementation mimics the original code and should thus work identically. Ideally, it would just call that code, but this method is not static and so cannot be directly called. This seemed simpler than getting that parent callable.
The tests are added to the
LinkCreateTest.php
because the tag find-or-create is called from the link creating/updating code. It has been a while since I worked on a project with unit tests, let me know if this is not how it's supposed to be done.Future work
firstOrCreate
is not called but case-insensitivity should be maintained, or the behavior is otherwise unexpected