Skip to content

Commit 8c45694

Browse files
committed
Escape comment text
1 parent bd820b9 commit 8c45694

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/invidious.cr

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,9 +1890,13 @@ get "/api/v1/comments/:id" do |env|
18901890
node_comment = node["commentRenderer"]
18911891
end
18921892

1893-
contentHtml = node_comment["contentText"]["simpleText"]?.try &.as_s.rchop('\ufeff')
1894-
contentHtml ||= node_comment["contentText"]["runs"].as_a.map do |run|
1895-
text = run["text"].as_s
1893+
content_html = node_comment["contentText"]["simpleText"]?.try &.as_s.rchop('\ufeff')
1894+
if content_html
1895+
content_html = HTML.escape(content_html)
1896+
end
1897+
1898+
content_html ||= node_comment["contentText"]["runs"].as_a.map do |run|
1899+
text = HTML.escape(run["text"].as_s)
18961900

18971901
if run["text"] == "\n"
18981902
text = "<br>"
@@ -1924,7 +1928,7 @@ get "/api/v1/comments/:id" do |env|
19241928
text
19251929
end.join.rchop('\ufeff')
19261930

1927-
contentHtml, content = html_to_content(contentHtml)
1931+
content_html, content = html_to_content(content_html)
19281932

19291933
author = node_comment["authorText"]?.try &.["simpleText"]
19301934
author ||= ""
@@ -1953,7 +1957,7 @@ get "/api/v1/comments/:id" do |env|
19531957
published = decode_date(node_comment["publishedTimeText"]["runs"][0]["text"].as_s.rchop(" (edited)"))
19541958

19551959
json.field "content", content
1956-
json.field "contentHtml", contentHtml
1960+
json.field "contentHtml", content_html
19571961
json.field "published", published.epoch
19581962
json.field "likeCount", node_comment["likeCount"]
19591963
json.field "commentId", node_comment["commentId"]

0 commit comments

Comments
 (0)