Answers.Body: <p>I feel your pain. Using wysiwyg editors to write emails is like using salt to heal a bleeding wound. It might have a purpose, but probably not in this context. and in this context, it hurts. A lot.</p>
  
  <p>Anyway, back to your question: are you having the replacement in the href or "only" when you leave the link as part of the text you send?</p>
  
  <p>The latest version of civi should behave correctly, otherwise, you can disable the replacement of the &amp; into &amp; (I've done it, it's not 100% html strict compatible, but seems to work fine with 100% of the real mail clients): here's an explanation on how to do it:
  <a href="https://civicrm.stackexchange.com/questions/7212/escaping-quotes-in-ckeditor-breaks-smarty-syntax">Escaping quotes in ckeditor breaks smarty-syntax</a></p>
  
  <p>and a more generic question about how to disable the wysiwyg editor:
  <a href="https://civicrm.stackexchange.com/questions/8107/how-to-disable-or-fix-the-wysiwyg-editor-on-civimail?rq=1">How to disable or fix the wysiwyg editor on civimail</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-14T14:24:40.420Z
Answers.Text: Okay, that makes sense.  Thank you for the links! Is there any reason that the built-in configuration for CKEditor is so limited? It only lets you change which buttons show up.  I think having functionality to do that would be very helpful.
Answers.UserDisplayName: Brad Xanti
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-14T14:29:00.207Z
Answers.Text: And to answer your question, it only replaces the `&`'s to `&amp;`'s when I switch back from editing the source to WYSIWYG view.  If I click to go to the next step without going back to WYSIWYG view, the link retains its `&`'s.
Answers.UserDisplayName: Brad Xanti
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-14T19:00:43.137Z
Answers.Text: I'm having this same problem, and we're on wordpress 4.4.6 and Civi 4.7.6 - which I understand is the latest. We've been having this issue since the upgrading to 4.7 and it's very cumbersome to train volunteers to do a workaround like this. So, it appears an upgrade doesn't solve it. The problem is in Civi still.
Answers.UserDisplayName: Ben
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-14T13:14:20.627Z
Answers.LastActivityDate: 2016-03-14T13:14:20.627Z
Answers.LastEditDate: 2017-04-13T12:53:13.017Z
Answers.UserDisplayName: Xavier
Answers.Body: <p>From my tests, it seems like this mostly happens when the URL goes through the URL tracking of CiviCRM.</p>
  
  <p>For example, if I send myself a test email from CiviMail, the URL will have a <code>&amp;amp;</code> in the URL, but my browser/email reader doesn't mind.</p>
  
  <p>It only becomes a problem when I do a full mailing and track the URL:</p>
  
  <pre><code>$ wget -O /dev/null -S "https://example.org/sites/all/modules/civicrm/extern/url.php?u=1234&amp;qid=87654"
    HTTP/1.1 302 Found
    Location: https://example.org/civicrm/event/info?reset=1&amp;amp;id=678
  </code></pre>
  
  <p>In that case, the URL causes a CiviCRM fatal error.</p>
  
  <p>Edit: this is by no means a proper solution, but in the mean time I am using this fix:</p>
  
  <pre><code>diff --git a/CRM/Mailing/Event/BAO/TrackableURLOpen.php b/CRM/Mailing/Event/BAO/TrackableURLOpen.php
  index 18e3284..0840e3d 100644
  --- a/CRM/Mailing/Event/BAO/TrackableURLOpen.php
  +++ b/CRM/Mailing/Event/BAO/TrackableURLOpen.php
  @@ -90,6 +90,10 @@ class CRM_Mailing_Event_BAO_TrackableURLOpen extends CRM_Mailing_Event_DAO_Track
       $open-&gt;time_stamp = date('YmdHis');
       $open-&gt;save();
  
  +    $search-&gt;url = preg_replace('/&amp;amp;/', '&amp;', $search-&gt;url);
  +
       return $search-&gt;url;
     }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-20T15:56:21.670Z
Answers.Text: Thanks for the fix! So, is this something we should put in the issue tracker? Seems like potentially a pretty big issue.
Answers.UserDisplayName: Brad Xanti
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-20T15:58:07.850Z
Answers.Text: Yep please do. This seems to affect a lot of people. I just ran into the issue again for another organisation, so I am now patching all my clients.
Answers.UserDisplayName: bgm
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-20T16:03:30.397Z
Answers.Text: Sorry, I'm not really familiar with how to do that. I'm happy to submit it, I just don't know how.
Answers.UserDisplayName: Brad Xanti
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-20T16:11:46.613Z
Answers.Text: You can create a new issue here: https://issues.civicrm.org - just enter a clear title based on this thread, and a link to this page. Post the link in a comment here too. I'll go fill in the details if necessary. I would do it for you, but you profile says you are a programmer, so may as well take the opportunity ;-)
Answers.UserDisplayName: bgm
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-23T13:57:06.270Z
Answers.Text: https://issues.civicrm.org/jira/browse/CRM-18657  There we go!
Answers.UserDisplayName: Brad Xanti
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-23T14:58:40.397Z
Answers.Text: Originally raised here, and already fixed in 4.7.8 =] Please do test this as part of the testing week for the new release candidate! https://issues.civicrm.org/jira/browse/CRM-18320
Answers.UserDisplayName: John
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-18T21:23:50.787Z
Answers.LastActivityDate: 2016-05-20T12:19:40.147Z
Answers.LastEditDate: 2016-05-20T12:19:40.147Z
Answers.UserDisplayName: bgm
Answers.Body: <p>There's two things here.</p>
  
  <p>The first is where the link is to. That should not contain the amp;s. You should only be able to see this in the source.</p>
  
  <p>The next is how the link appears. This bit should contain the amp;s to make it HTML friendly.</p>
  
  <p>Links in source view should be of the form: </p>
  
  <pre><code>Click &lt;a href="http://linknotcontainingamps.net"&gt;http://linkcontainingamps.net&lt;/a&gt;
  </code></pre>
  
  <p>Or even</p>
  
  <pre><code>Click &lt;a href="http://linknotcontainingamps.net"&gt;here&lt;/a&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-14T14:07:17.353Z
Answers.Text: Well, that's actually what it does look like.  It looks something like this: `<a href=".../index.php?option=com_civicrm&id=172&lang=en&reset=1&task=civicrm/event/register">RSVP Here</a>`.  The problem that's happening is that when I switch from editing the source to the WYSIWYG view, it replaces all of the `&`s inside of the href to `&amp;`s, thus jumbling the URL the link leads to.
Answers.UserDisplayName: Brad Xanti
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-11T23:13:04.383Z
Answers.LastActivityDate: 2016-03-11T23:13:04.383Z
Answers.UserDisplayName: JohnFF
Answers.Body: <p>CORRECTED: I too am having this problem &amp; it has also been happening with my Civi/Wordpress &amp; Civi/Drupal sites since 4.7 upgrade. Adding a link to an event or contribution page via the link button seems to work fine, but the resultant html code contains escaped ampersands (these don't show when the link is reopened using the link button) that make the link unusable. As noted above, the only workaround seems to be to correct the source and then not use WYSIWYG again - frustrating if you have content corrections to make thereafter.</p>
  
  <p>I have applied the various CKEditor configuration directives suggested in the links above to media/civicrm/persist/crm-ckeditor-config.js with no result. I can confirm that other directives when used here cause corresponding changes in the editor (e.g style or help buttons), but the config.entities directives etc don't affect escape processing.</p>
  
  <p>This doesn't seems to be an issue with CKEditor, as the same link inserted into an Event description works perfectly well, so must be an issue with the Civimail implementation.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-07T04:33:02.517Z
Answers.LastActivityDate: 2016-04-21T01:40:46.703Z
Answers.LastEditDate: 2016-04-21T01:40:46.703Z
Answers.UserDisplayName: Bryan
Body: <p>I'm trying to send out a mailing via CiviMail, and we have a link to the RSVP URL of our CiviCRM event.  However, whenever we've sent out the test emails, it seems that the URL is getting messed up by the included WYSIWYG: CKEditor.  This is the problem we are experiencing.  If you take a URL, say </p>
  
  <pre><code>http://example.com/index.php?option=com_civicrm&amp;id=172&amp;lang=en&amp;reset=1&amp;task=civicrm/event/register
  </code></pre>
  
  <p>It gets replaced with the following URL:</p>
  
  <pre><code>http://example.com/index.php?option=com_civicrm&amp;amp;id=172&amp;amp;lang=en&amp;amp;reset=1&amp;amp;task=civicrm/event/register
  </code></pre>
  
  <p>Now the difference isn't all that noticeable, but the <code>&amp;</code>s get replaced with <code>&amp;amp;</code>s.  I was able to find a workaround by editing the source of the email and replacing all of the <code>&amp;amp;</code>s and not switching back to WYSIWYG view before sending it out.  However this a less-than-ideal, band-aid solution.  Does anyone have an idea of how to fix this issue?</p>
  
  <p><em>note: I tried installing the TinyMCE CiviCRM extension, and that did not solve the problem, the URL's were still getting jumbled.</em></p>
  
Tags: <civimail><ckeditor>
Title: WYSIWYG Editor Messing with URL's
ThreadText: # WYSIWYG Editor Messing with URL's
  
  (Asked by: username_0 on 2016-03-11)
  
  I'm trying to send out a mailing via CiviMail, and we have a link to the RSVP URL of our CiviCRM event. However, whenever we've sent out the test emails, it seems that the URL is getting messed up by the included WYSIWYG: CKEditor. This is the problem we are experiencing. If you take a URL, say
  
  ```
  http://example.com/index.php?option=com_civicrm&id=172&lang=en&reset=1&task=civicrm/event/register
  
  ```
  
  It gets replaced with the following URL:
  
  ```
  http://example.com/index.php?option=com_civicrm&amp;id=172&amp;lang=en&amp;reset=1&amp;task=civicrm/event/register
  
  ```
  
  Now the difference isn't all that noticeable, but the `&`s get replaced with `&amp;`s. I was able to find a workaround by editing the source of the email and replacing all of the `&amp;`s and not switching back to WYSIWYG view before sending it out. However this a less-than-ideal, band-aid solution. Does anyone have an idea of how to fix this issue?
  
  *note: I tried installing the TinyMCE CiviCRM extension, and that did not solve the problem, the URL's were still getting jumbled.*
  
  **Tags:** civimail, ckeditor
  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_1 on 2016-03-14. Score: 3
  
  I feel your pain. Using wysiwyg editors to write emails is like using salt to heal a bleeding wound. It might have a purpose, but probably not in this context. and in this context, it hurts. A lot.
  
  Anyway, back to your question: are you having the replacement in the href or "only" when you leave the link as part of the text you send?
  
  The latest version of civi should behave correctly, otherwise, you can disable the replacement of the & into & (I've done it, it's not 100% html strict compatible, but seems to work fine with 100% of the real mail clients): here's an explanation on how to do it:
  [Escaping quotes in ckeditor breaks smarty-syntax](https://civicrm.stackexchange.com/questions/7212/escaping-quotes-in-ckeditor-breaks-smarty-syntax)
  
  and a more generic question about how to disable the wysiwyg editor:
  [How to disable or fix the wysiwyg editor on civimail](https://civicrm.stackexchange.com/questions/8107/how-to-disable-or-fix-the-wysiwyg-editor-on-civimail?rq=1)
  
  > **Comments:**
  > **username_0**: Okay, that makes sense.  Thank you for the links! Is there any reason that the built-in configuration for CKEditor is so limited? It only lets you change which buttons show up.  I think having functionality to do that would be very helpful.  
  > **username_0**: And to answer your question, it only replaces the `&`'s to `&amp;`'s when I switch back from editing the source to WYSIWYG view.  If I click to go to the next step without going back to WYSIWYG view, the link retains its `&`'s.  
  > **username_2**: I'm having this same problem, and we're on wordpress 4.4.6 and Civi 4.7.6 - which I understand is the latest. We've been having this issue since the upgrading to 4.7 and it's very cumbersome to train volunteers to do a workaround like this. So, it appears an upgrade doesn't solve it. The problem is in Civi still.  
  
  ---
  
  ### Answer by username_3 on 2016-05-18. Score: 2
  
  From my tests, it seems like this mostly happens when the URL goes through the URL tracking of CiviCRM.
  
  For example, if I send myself a test email from CiviMail, the URL will have a `&amp;` in the URL, but my browser/email reader doesn't mind.
  
  It only becomes a problem when I do a full mailing and track the URL:
  
  ```
  $ wget -O /dev/null -S "https://example.org/sites/all/modules/civicrm/extern/url.php?u=1234&qid=87654"
    HTTP/1.1 302 Found
    Location: https://example.org/civicrm/event/info?reset=1&amp;id=678
  
  ```
  
  In that case, the URL causes a CiviCRM fatal error.
  
  Edit: this is by no means a proper solution, but in the mean time I am using this fix:
  
  ```
  diff --git a/CRM/Mailing/Event/BAO/TrackableURLOpen.php b/CRM/Mailing/Event/BAO/TrackableURLOpen.php
  index 18e3284..0840e3d 100644
  --- a/CRM/Mailing/Event/BAO/TrackableURLOpen.php
  +++ b/CRM/Mailing/Event/BAO/TrackableURLOpen.php
  @@ -90,6 +90,10 @@ class CRM_Mailing_Event_BAO_TrackableURLOpen extends CRM_Mailing_Event_DAO_Track
       $open->time_stamp = date('YmdHis');
       $open->save();
  
  +    $search->url = preg_replace('/&amp;/', '&', $search->url);
  +
       return $search->url;
     }
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks for the fix! So, is this something we should put in the issue tracker? Seems like potentially a pretty big issue.  
  > **username_3**: Yep please do. This seems to affect a lot of people. I just ran into the issue again for another organisation, so I am now patching all my clients.  
  > **username_0**: Sorry, I'm not really familiar with how to do that. I'm happy to submit it, I just don't know how.  
  > **username_3**: You can create a new issue here: https://issues.civicrm.org - just enter a clear title based on this thread, and a link to this page. Post the link in a comment here too. I'll go fill in the details if necessary. I would do it for you, but you profile says you are a programmer, so may as well take the opportunity ;-)  
  > **username_0**: https://issues.civicrm.org/jira/browse/CRM-18657  There we go!  
  > **username_4**: Originally raised here, and already fixed in 4.7.8 =] Please do test this as part of the testing week for the new release candidate! https://issues.civicrm.org/jira/browse/CRM-18320  
  
  ---
  
  ### Answer by username_5 on 2016-03-11. Score: 1
  
  There's two things here.
  
  The first is where the link is to. That should not contain the amp;s. You should only be able to see this in the source.
  
  The next is how the link appears. This bit should contain the amp;s to make it HTML friendly.
  
  Links in source view should be of the form:
  
  ```
  Click <a href="http://linknotcontainingamps.net">http://linkcontainingamps.net</a>
  
  ```
  
  Or even
  
  ```
  Click <a href="http://linknotcontainingamps.net">here</a>
  
  ```
  
  > **Comments:**
  > **username_0**: Well, that's actually what it does look like.  It looks something like this: `<a href=".../index.php?option=com_civicrm&id=172&lang=en&reset=1&task=civicrm/event/register">RSVP Here</a>`.  The problem that's happening is that when I switch from editing the source to the WYSIWYG view, it replaces all of the `&`s inside of the href to `&amp;`s, thus jumbling the URL the link leads to.  
  
  ---
  
  ### Answer by username_6 on 2016-04-07. Score: 1
  
  CORRECTED: I too am having this problem & it has also been happening with my Civi/Wordpress & Civi/Drupal sites since 4.7 upgrade. Adding a link to an event or contribution page via the link button seems to work fine, but the resultant html code contains escaped ampersands (these don't show when the link is reopened using the link button) that make the link unusable. As noted above, the only workaround seems to be to correct the source and then not use WYSIWYG again - frustrating if you have content corrections to make thereafter.
  
  I have applied the various CKEditor configuration directives suggested in the links above to media/civicrm/persist/crm-ckeditor-config.js with no result. I can confirm that other directives when used here cause corresponding changes in the editor (e.g style or help buttons), but the config.entities directives etc don't affect escape processing.
  
  This doesn't seems to be an issue with CKEditor, as the same link inserted into an Event description works perfectly well, so must be an issue with the Civimail implementation.
  
  
  ---
  
  