Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Fix <br> tag duplicated (#1575)

The bug came from bbcode parser which transforms \n with <br>.
So I just remove the br tag in bbcode parser before applying the mardown parser.
Fix #1480
Cette révision appartient à :
akuma06 2017-09-17 21:47:17 +02:00 révisé par kilo
Parent 421935f8be
révision 0646d9fc0c
2 fichiers modifiés avec 4 ajouts et 1 suppressions

Voir le fichier

@ -310,6 +310,7 @@ func repairHTMLTags(brokenHTML string) string {
// ParseBBCodes returns the bbcode compiler with the bbcode tags to parse
func ParseBBCodes(msg string) string {
msg = BBCodesRenderer.Compile(msg)
msg = strings.Replace(msg, "<br>", "\n", -1)
// For some reason, BBCodes compiler return escaped html
// We need to unescape it
return html.UnescapeString(msg)

Voir le fichier

@ -36,6 +36,7 @@ func TestParseBBCodes(t *testing.T) {
{"", ""},
{"&gt;", "&gt;"}, // keep escaped html
{"<b>lol</b>", "<b>lol</b>"}, // keep html tags
{"ddd\nddd", "ddd\nddd"}, // keep html tags
{"[b]lol[/b]", "<b>lol</b>"}, // Convert bbcodes
{"[u][b]lol[/u]", "<u><b>lol</b></u>"}, // Close unclosed tags
}
@ -71,7 +72,8 @@ func TestSanitize(t *testing.T) {
Result string
}{
{"", ""},
{"[b]lol[/b]", "<b>lol</b>"}, // Should convert bbcodes
{"[b]lol[/b]", "<b>lol</b>"}, // Should convert bbcodes
{"ddd\nddd", "ddd\nddd"},
{"&gt;", "&gt;"}, // keep escaped html
{"<b>lol</b>", "<b>lol</b>"}, // keep html tags
{"<b><u>lol</b>", "<b><u>lol</u></b>"}, // close unclosed tags encapsulated