Opened 8 years ago
Last modified 8 years ago
#7125 new defect (bug)
Apostrophe not handled correctly in activity filter array.
Reported by: | IdleWanderer | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Contributions | Priority: | normal |
Severity: | normal | Version: | 2.2 |
Component: | Activity | Keywords: | |
Cc: |
Description
Hi!
I posted this in the support forum, and someone suggested it probably is a bug. So here's the issue:
Basically, this is what I want and what I am doing so far:
If a user writes about a specific species of animal, whatever the user wrote will come up on the activity stream for the page for that particular species, as long as the name of the species is mentioned. Now, this I can do (thanks to help in the forums), but a few animals have a species name with an apostrophe in it, and that’s where my problem arises.
Here’s an example of what I want done:
function my_bp_activities_search_term_on_page_3431( $retval ) { // Add search term for correct page if ( is_page(3431) ) { $filter_query[] = array( 'relation' => 'OR', array( 'column' => 'content', 'value' => 'keast's tube-nosed fruit bat', 'compare' => 'LIKE' ), array( 'column' => 'content', 'value' => 'keast's tube-nosed bat', 'compare' => 'LIKE' ), array( 'column' => 'content', 'value' => 'nyctimene keasti', 'compare' => 'LIKE' ), ); $retval['filter_query'] = $filter_query; } return $retval; } add_filter( 'bp_after_has_activities_parse_args', 'my_bp_activities_search_term_on_page_3431' );
Of course, I got an error doing this.
I tried solving this in two ways. First, by escaping, like this:
'value' => 'keast\'s tube-nosed fruit bat',
And again, doing this:
'value' => "keast's tube-nosed fruit bat",
Both of them worked in the sense that there were no errors, but neither of them worked when it came to actually showing the term with the apostrophe. Which is the whole point in the first place. The conclusion in the forum was it likely is a bug that doesn't handle the apostrophe correctly upstream.
So, is this a bug, and can it be fixed?
Thanks,
Havard
Attachments (1)
Change History (7)
#1
@
8 years ago
- Component changed from (not sure) to Activity
- Keywords reporter-feedback added
- Version changed from 2.5.0 to 2.2
#2
@
8 years ago
- Milestone changed from Awaiting Review to Future Release
Our handling of slashed data is inconsistent and horrible, sorry that you've had this problem.
#3
@
8 years ago
- Component changed from Activity to (not sure)
- Milestone changed from Future Release to Awaiting Review
- Version changed from 2.2 to 2.5.0
Thanks for getting back to me on this!
r-a-y: I've tried that already. It doesn't work for me.
DJPaul: Ok, glad to ear it is a real issue, and not just an issue for me. So, you will be working to solve it in a future release?
#4
@
8 years ago
- Component changed from (not sure) to Activity
- Keywords reporter-feedback removed
- Milestone changed from Awaiting Review to Future Release
- Version changed from 2.5.0 to 2.2
I see I changed everything.. I'll just change it back.
#5
@
8 years ago
- Keywords reporter-feedback added
- Milestone changed from Future Release to Awaiting Review
I can't duplicate this issue. You shouldn't need to add backslashes; BuddyPress already is smart enough to escape it.
I've attached a unit test that is working for me.
#6
@
8 years ago
- Keywords reporter-feedback removed
- Milestone changed from Awaiting Review to Future Release
I see. I've also been using " to solve the issue, as I showed above in the ticket. For me, however, terms won't show in the activity stream on the page where it should when there is an apostrophe present. If I remove the apostrophe from the term in the filter, and post an activity update that includes the term without an apostrophe, it shows as it should on the correct page. As soon as I add an apostrophe to it, it just will not show.
I am not very good at coding, and there was a guy from the support forum who basically created the whole filter-array for me. However, I understood how that one worked, and have been able duplicate it for lots of pages. But if you did something clever to make it work with apostrophes in the attachment (besides wrapping the term in "), then I am probably not smart enough to see it.
When you add an apostrophe in your activity content, we have to add a backslash when inserted into the database.
So in your filter, try adding a backslash before the apostrophe. eg.
keast\'s tube-nosed bat