title: How to sanitize all unicode characters in the Url
body: <p>We have an chat based app, where our customer rep chats with the end user. Recently our security team found an issue with our app, where the user can inject a homograph version of the Url in the chat window.</p>
  <p><strong>example:</strong>
  if the end user types the below question in the chat window:
  How to change my email settings at <a href="http://www.xn--abcs-75d.ca" rel="nofollow noreferrer">http://www.abcоs.ca</a></p>
  <p>In the above example, site is homographed version, where in &quot;оs.ca&quot; is non ascii character, whereas the original url could be <a href="http://www.abcos.ca" rel="nofollow noreferrer">http://www.abcos.ca</a>
  (I just made up these url examples)</p>
  <p>so I tried to use the below code in my javascript:</p>
  <pre><code>var chatMessage = 'How to change my email settings at http://www.abcоs.ca'
  chatMessage.normalize('NFD').replace(/[^\u0000-\u007f]/g, '');
  </code></pre>
  <p>the above script works well and it strips off the non ascii character, but then we have support for both English and French chat,</p>
  <p>in French if the chatMessage is &quot;Comment modifier mes paramètres de messagerie sur <a href="http://www.xn--abcs-75d.ca" rel="nofollow noreferrer">http://www.abcоs.ca</a></p>
  <p>then it replaces &quot;è&quot; with &quot;e&quot; in the sanitized version.</p>
  <p>Wondering if there is a way to detect the non ascii character within an url from the input text value in javascript, so that the expect outcome would be:
  &quot;Comment modifier mes paramètres de messagerie sur http://www.abc&quot;
  so that french characters are still retained in the text, but the within url's the non ascii characters are sanitized.</p>
  <p>Appreciate expert advice and guidance.</p>