JetBrains / markdown

Markdown parser written in kotlin
Apache License 2.0
682 stars 75 forks source link

Incorrect unescaping of HTML entities #32

Closed kkononov closed 4 years ago

kkononov commented 6 years ago

With input containing < and > (in the escaped form), we end up having incorrect HTML.

Example input: &lt;wrongTag&gt; Output HTML: <wrongTag>

Not sure, but the same problem may be with &amp; (in the escaped form)

The reason is in what EntityConverter#replaceEntities(text: CharSequence, processEntities: Boolean, processEscapes: Boolean) does when called with true values of arguments.

valich commented 4 years ago

It turned out to be bloody Kotlin JS. The following test:

private val replacements: Map<Char, String> = mapOf(
            '<' to "&lt;",
            '>' to "&gt;"
    )

println("${replacements[60.toChar()]} ${60.toChar().let {replacements[it]}} ${60.toChar()?.let {replacements[it]}}")

prints &lt; &lt; null.

I'll rewrite code in another way.

valich commented 4 years ago

Fixed in 55dcc1b0ff57378891d9fc8ef718d09a414e1c65, JS-only problem.

Available in kotlin-js-clean branch, 0.2.0-pre-7 is published as well