Skip to:
Content

Opened 22 months ago

Closed 20 months ago

Last modified 20 months ago

#6966 closed defect (bug) (fixed)

Email Subject special characters display problem with initiator.name token (BuddyPress v2.5.1)

Reported by: richdal Owned by: r-a-y
Milestone: 2.5.3 Priority: high
Severity: normal Version: 2.5.0
Component: Emails Keywords: has-patch commit
Cc:

Description

Original post to Support https://buddypress.org/support/topic/special-characters-in-initiator-name-token/

Running into a problem with special characters in the initiator.name email token. If the name has a special character like an apostrophe (e.g. O'Neil) that token displays fine in the email message body. On the message's Subject though it appears as...

[RGP] New friendship request from Tom O'Neil

Had a recommendation to try a filter using stripslashes() such as this...

apply_filters( 'bp_email_set_subject', $subject, $this );
function RGP_email_subject( $subject, $obj ) {
     $subject = stripslashes( $subject );
    return $subject;
}
add_filter( 'bp_email_set_subject', 'RGP_email_subject', 15, 2 );

I used that specifically but it did not affect the Subject text.

I tried a different version of that below. I was able to get the extra string of text appended to $subject, but couldn't get either version of the str_replace() to change the problem text...

apply_filters( 'bp_email_set_subject', $subject, $this );
function RGP_email_subject( $subject, $obj ) {
     $subject = stripslashes( $subject );

    //tried this 1st
    //$subject = str_replace( ''', "'", $subject );

    //tried this 2nd
    //$subject = addslashes( str_replace( ''', "'", $subject ) );

    //tried this 3rd
    $subject = str_replace( ''', "TEST", $subject );

    $subject .= " append custom text";
    return $subject;
}
add_filter( 'bp_email_set_subject', 'RGP_email_subject', 15, 2 );

Attachments (2)

tests-in-progress.diff (1.8 KB) - added by DJPaul 21 months ago.
6966.01.patch (2.8 KB) - added by r-a-y 21 months ago.

Download all attachments as: .zip

Change History (19)

#1 @DJPaul
22 months ago

  • Milestone changed from Awaiting Review to 2.5.2

#2 @DJPaul
22 months ago

For this, we need to filter the get_subject() with wp_specialchars_decode( $the_value, ENT_QUOTES ) which should do it.

#3 @DJPaul
22 months ago

And probably do the same for the "From Name", "To Names", "BCC Names", "CC Names".

We already do this for the default value of "From Name", but we should make sure it's always done.

#4 @DJPaul
22 months ago

Or maybe in the "set" filters instead of "get". Not sure.

#5 @DJPaul
22 months ago

  • Component changed from API to API - Emails
  • Priority changed from normal to high

This ticket was mentioned in Slack in #buddypress by djpaul. View the logs.


22 months ago

#7 @DJPaul
22 months ago

  • Version set to 2.5.0

#8 @DJPaul
22 months ago

  • Milestone changed from 2.5.2 to 2.5.3

#9 @DJPaul
22 months ago

  • Keywords needs-patch added

This ticket was mentioned in Slack in #buddypress by dcavins. View the logs.


21 months ago

#11 @DJPaul
21 months ago

@r-a-y mentioned this ticket in the dev meeting today. I've added a patch of tests I was trying to write to prove the problem, but I was struggling to do that. I couldn't get the right kind of character entity in my test.

@r-a-y
21 months ago

#12 @r-a-y
21 months ago

  • Keywords has-patch added; needs-patch removed

@DJPaul - I've attached a patch for the email subject decoding issue.

What we were lacking was HTML decoding when fetching the email subject. I'm also switching when we use html_entity_decode(); we should only do this when $transform is set to replace-tokens.

I've also modified the unit tests. The first test in tests-in-progress.diff uses wptexturize(), which will not be used; when we fetch the email post, post title is always raw. Second test has been simplified.

Let me know what you think.

#13 @DJPaul
21 months ago

I can't test the patch at the moment but it looks pretty good!

#14 @DJPaul
21 months ago

Can we get this tested by someone please and committed? It's blocking 2.5.3 which has more important email fixes in.

#15 @DJPaul
21 months ago

  • Keywords commit added

Gave this a quick test, seems to fix it. Thanks @r-a-y!

#16 @r-a-y
20 months ago

  • Owner set to r-a-y
  • Resolution set to fixed
  • Status changed from new to closed

In 10760:

Emails: Ensure that the email subject is HTML entity-decoded.

Fixes an issue when using email tokens that contain HTML special characters
in the email subject.

Fixes #6966 (2.5-branch)

#17 @r-a-y
20 months ago

In 10761:

Emails: Ensure that the email subject is HTML entity-decoded.

Fixes an issue when using email tokens that contain HTML special characters
in the email subject.

See #6966 (trunk)

Note: See TracTickets for help on using tickets.