Contact Form: wrong subject line when site title includes an apostrophe
Steps to reproduce:
- Create a default form (no custom options, just add the form without editing the form content) using the form builder: the shortcode will be as follows:
[contact-form][contact-field label='Name' type='name' required='1'/][contact-field label='Email' type='email' required='1'/][contact-field label='Website' type='url'/][contact-field label='Comment' type='textarea' required='1'/][/contact-form]
- Go to Settings > General in your dashboard, and change your site title to include an apostrophe, e.g. "the cat's pajamas"
- Insert a default form again: the shortcode now includes a subject line, including a square bracket:
[contact-form subject='[the cat%26#039;s pajamas'][contact-field label='Name' type='name' required='1'/][contact-field label='Email' type='email' required='1'/][contact-field label='Website' type='url'/][contact-field label='Comment' type='textarea' required='1'/][/contact-form]
Reported in #2065950-org
I think this is what's happening:
- A default subject is generated
- The attributes (including the subject) are passed through unesc_attr(). Certain characters in particular (" ' & ,) are unencoded.
- After passing through some other steps this value is compared to the saved default. When they are found to be different (due to step 2) the code falsely concludes that the user has set the subject to this value and includes it in the shortcode (escaped again later in the function).
Looking back at this code, adding an esc_attr (as shown below) seems to solve the problem. I would appreciate a 2nd opinion as I don't feel I've entirely got to grips with this code just yet, but I can make a pull request if desired.
if ( isset( $this->defaults[$key] ) && $this->defaults[$key] == esc_attr( $value ) ) {
continue;
}
This issue has been marked as stale. This happened because:
- It has been inactive in the past 6 months.
- It hasn’t been labeled `[Pri] Blocker`, `[Pri] High`.
No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.
This issue has been marked as stale. This happened because:
- It has been inactive in the past 6 months.
- It hasn’t been labeled `[Pri] Blocker`, `[Pri] High`, etc.
No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.