Forum

Thread tagged as: Question, Problem, Error

unescaped < and >

If I insert <, &lt;, >, or &gt; into a markdown textarea, Perch outputs them as raw < and > chars, which causes validation errors (e.g. "Bad character after <. Probable cause: Unescaped <. Try escaping it as <."). Is there any way to properly escape these?

David Newton

David Newton 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Do you have html="true" set? Otherwise they'll be encoded automatically.

Yes, the fields have html="true" set. The fields contain fairly complex tables, so I need to be able to enter HTML in them.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

If you have html="true" set then Perch is behaving correctly and not escaping HTML tags. It isn't possible to have it both ways.

Hmm… my thought was that having html="true" would allow me to do proper HTML character encoding, e.g. &lt;. The problem is that this sequence of characters is getting converted to a literal '<' at some point before being output. That doesn't seem like correct behaviour. If html="true" is set, shouldn't the &lt; get output exactly as entered?

I just did a quick check and this isn't happening if markdown isn’t also set to true; with just html="true" set, I can enter &lt; and it is output exactly as I entered it. So, it looks like an issue with ParseDown converting &lt; to <, not Perch.

Sorry for the multiple posts. I just checked Parsedown and it's actually handling this properly.

I think the problem is in core/lib/PerchFieldTypes.class.php, line 496. This block is decoding HTML entities because markdown="true", but that should probably only happen if markdown="true" and html="false".

Drew McLellan

Drew McLellan 2638 points
Perch Support

html is false unless it's set to true. If it's not set to true, < should output as &lt; in the source.