Sanitize XML to remove invalid characters

Fixes #268
This commit is contained in:
Zed 2020-11-07 23:53:49 +01:00
parent 375cb1a243
commit d358912790
2 changed files with 6 additions and 2 deletions

View File

@ -14,6 +14,7 @@ const
manifestRegex = re"(.+(.ts|.m3u8|.vmap))"
userpicRegex = re"_(normal|bigger|mini|200x200|400x400)(\.[A-z]+)$"
extRegex = re"(\.[A-z]+)$"
illegalXmlRegex = re"[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u10000-\u10FFFF]"
twitter = parseUri("https://twitter.com")
@ -26,6 +27,9 @@ proc stripHtml*(text: string): string =
el[0].text = link
html.innerText()
proc sanitizeXml*(text: string): string =
text.replace(illegalXmlRegex, "")
proc shortLink*(text: string; length=28): string =
result = text.replace(wwwRegex, "")
if result.len > length:

View File

@ -69,7 +69,7 @@
#var title = profile.fullname
#if not multi: title &= " / " & user
#end if
#title = xmltree.escape(title)
#title = xmltree.escape(title).sanitizeXml
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
<channel>
@ -86,7 +86,7 @@
<width>128</width>
<height>128</height>
</image>
# if timeline.content.len > 0:
#if timeline.content.len > 0:
${renderRssTweets(timeline.content, prefs, hostname)}
#end if
</channel>