Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Unescape HTML entities in oEmbed title #14781

Merged
merged 6 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/14781.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unescape HTML entities in Open Graph title.
3 changes: 2 additions & 1 deletion synapse/rest/media/v1/oembed.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import html as html5
JeyRathnam marked this conversation as resolved.
Show resolved Hide resolved
import logging
import urllib.parse
from typing import TYPE_CHECKING, List, Optional
Expand Down Expand Up @@ -161,7 +162,7 @@ def parse_oembed_response(self, url: str, raw_body: bytes) -> OEmbedResult:

title = oembed.get("title")
if title and isinstance(title, str):
open_graph_response["og:title"] = title
open_graph_response["og:title"] = html5.unescape(title)
JeyRathnam marked this conversation as resolved.
Show resolved Hide resolved

author_name = oembed.get("author_name")
if not isinstance(author_name, str):
Expand Down
10 changes: 10 additions & 0 deletions tests/rest/media/v1/test_oembed.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,13 @@ def test_link(self) -> None:
result = self.parse_response({"type": "link"})
self.assertIn("og:type", result.open_graph_result)
self.assertEqual(result.open_graph_result["og:type"], "website")

def test_title_html_entities(self) -> None:
"""Test HTML entities in title"""
result = self.parse_response(
{"title": "Why JSON isn’t a Good Configuration Language"}
)
self.assertEqual(
result.open_graph_result["og:title"],
"Why JSON isn’t a Good Configuration Language",
)