Search code examples
htmlpurifier

HTML Purifier filters out underscore (_) from URL when inserting hyperlink


On a website, I am inserting a link with a hyperlink inside, like so:

For more information <a href="https://example.com/sample_doc.html">read the docs</a>.

HTML Purifier is filtering out the entire URL, so that I'm not able to insert these URLs.

Output of HTML Purifier (by using the demo website):

For more information <a>read the docs</a>.

Is there a way to change the config, allowing HTML Purifier to allow underscores in my URLs?

I read the documentation of HTML Purifier but couldn't find an answer to my question.

My current config (default) looks like this:

{
  "Attr.AllowedFrameTargets": [
    "_blank"
  ],
  "Attr.EnableID": true,
  "HTML.AllowedComments": [
    "pagebreak"
  ],
  "HTML.SafeIframe": true,
  "URI.SafeIframeRegexp": "%^(https?:)?//(www.youtube.com/|player.vimeo.com/)%"
}

Solution

  • I found the solution in the documentation of HTML Purifier: http://htmlpurifier.org/live/configdoc/plain.html#Core.AllowHostnameUnderscore

    Adding the following code to the Default.json config file allows me to add underscores to hostnames and URLs now

    "Core.AllowHostnameUnderscore": true,