-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Saving comma separated tags is incorrect #299
Conversation
It seems you need to pass an option in order to parse tags with commas: jure.knowledge_list ='"WATFIV, WATFOR", hello', :parse => true but it doesn't seem to be documented anywhere and I think it's confusing. But does it work for you? |
@tilsammans This is not valid Ruby? My issue also isn't that the tags get parsed wrongly (they are), but that once the object they get re-parsed instead of remaining as they were, when the tags were set. It has to do with saving the tags to the database, if they contain a comma. I'll look into it more when I have time, but it seems that tags generally should just not contain commas in any case :) |
Well, it should be fine. I think the logic goes like this: jure.knowledge_list = "these, are, normal, tags"
jure.knowledge_list = '"this, is, a, single, tag", and, these, are separate' So, the split is always by delimiter, unless there are quotes, in which case the quotes win. But I see not a lot of test cases testing this behavior. So, it would be good to start adding failing specs. Are you in a position to add specs? If not, could you supply me with real IRB output that demonstrates the bugs? If you can please include the creation of the models too and leave out the database output. I am sure I can at least fix the most egregious bugs still in 2.4.x. |
Here's a single failing spec. Hope that helps. If you don't have time, I'll see what's up over the weekend. |
I think #386 is the valid Ruby you were looking for 😉 |
Would you mind rebasing against master and force-pushing? Thanks |
Done. Hope this helps you. Still fails on current master:
|
I believe this is a duplicate of #394 |
Assuming this is still an open issue, I should point out that the documentation suggests that
should parse the tags out. It does not, however, say what happens when you mix and match both a CSV-string and an array of additional values, as in the OP above:
I personally think it's perfectly reasonable to assume that this does in fact mean to treat "bar, baz, quux" as a single tag with commas in it (that is, that we're adding an array of 3 tags, not 5). So I'm not really sure there's a bug here at all. |
I wish it would do that. In your example, i.e.:
You would get tags I think that's a bug and what you're describing is what I think the correct behavior should be. |
@jure -- Not quite sure we're speaking to the same example, really. You've just introduced another case! Case #1: setting only an array
or
Will add five tags. Case #2: Add just a string
Will add five tags **Case #3: Adding a CSV string as part of an array
or, to be a bit more syntactically clear
Will add three tags: 'bar, baz, quux', 'quuux', and 'quuuux' **Case #4: Adding a CSV within a CSV
Personally, I would expect this to behave exactly like Case #3 above -- three tags, one of which contains commas. |
We are. In the bug I reported above, case #3 results in 5 tags (after .save and .reload). Before the .save and .reload it parses it correctly, i.e. into 3 tags, one of which contains commas. But they get saved as 5. I described this in my initial comment. |
@jure OK. I get it now. Thanks for clarifying. I agree that that is a bug (or if it isn't, the documentation should be updated to clarify all four cases, but I think it is). I'm taking an interest in the gem since I'm giving serious thought to using it in a project. If time allows, I may tackle this issue. |
Cool, I would appreciate it! |
@jure would you mind creating a failing test for this issue? And update the issue with a clearer description of the bug, as discussion here? And include an example in the README? |
Here's a mystery. I tried adding "WATFIV, WATFOR" as a tag, but it gets saved as WATFIV and WATFOR separately, even though tag_list correctly parses the string into 1 tag.
So even though the knowledge_list reader correctly parses the tags, the .save calls something else that parses the string incorrectly and splits the tags on that comma. Any ideas? I'll dig a bit deeper myself.