only add a closing quote if it is not already present #12182
Merged
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.
Overview
CiviMail was adding extra closing quotes to some tokens
Before
On dmaster, create a new mailing with the following content:
<p><a href="https://example.org/communication-preferences?cid1={contact.contact_id}&{contact.checksum}">Click here to select your communication preferences</a></p>
Send a test mailing
Note that the output is something like
<p><a href="https://example.org/communication-preferences?cid1=2&cs=cbfcef29ea6a8f4022b3d34e8259294d_1527000439_168&reset=1"">Click here to select your communication preferences</a></p>
This happens because the code assumes that the trailing quote is not present and that it needs to be added.
Some (it seems a minority) of email clients cannot handle the extra quote and the email is corrupted as a result.
After
Instead of assuming that the trailing quote is not present, we check to see if it is present and only add it if it is not present.
Comments
I did not want to mess with / try and understand why the code was gobbling up the trailing quote is some cases in the first place. TBH, I would have done the extra work normally but did not think it was worth it in this case seeings as we are moving to flexmailer TM (and this problem does not occur in flexmailer).
This fixes the problem in a minimally invasive way and meant that I did not have to try and understand the ins and outs of why the trailing quote is / is not being gobbled.