mirror of
https://github.com/sissbruecker/linkding
synced 2024-11-10 06:04:15 +00:00
Escape texts in exported HTML (#429)
This commit is contained in:
parent
89a9271c71
commit
74134d3896
2 changed files with 31 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
|||
import html
|
||||
from typing import List
|
||||
|
||||
from bookmarks.models import Bookmark
|
||||
|
@ -28,8 +29,8 @@ def append_list_start(doc: BookmarkDocument):
|
|||
|
||||
def append_bookmark(doc: BookmarkDocument, bookmark: Bookmark):
|
||||
url = bookmark.url
|
||||
title = bookmark.resolved_title
|
||||
desc = bookmark.resolved_description
|
||||
title = html.escape(bookmark.resolved_title or '')
|
||||
desc = html.escape(bookmark.resolved_description or '')
|
||||
tags = ','.join(bookmark.tag_names)
|
||||
toread = '1' if bookmark.unread else '0'
|
||||
added = int(bookmark.date_added.timestamp())
|
||||
|
|
28
bookmarks/tests/test_exporter.py
Normal file
28
bookmarks/tests/test_exporter.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
from django.test import TestCase
|
||||
|
||||
from bookmarks.services import exporter
|
||||
from bookmarks.tests.helpers import BookmarkFactoryMixin
|
||||
|
||||
|
||||
class ExporterTestCase(TestCase, BookmarkFactoryMixin):
|
||||
def test_escape_html_in_title_and_description(self):
|
||||
bookmark = self.setup_bookmark(
|
||||
title='<style>: The Style Information element',
|
||||
description='The <style> HTML element contains style information for a document, or part of a document.'
|
||||
)
|
||||
html = exporter.export_netscape_html([bookmark])
|
||||
|
||||
self.assertIn('<style>: The Style Information element', html)
|
||||
self.assertIn(
|
||||
'The <style> HTML element contains style information for a document, or part of a document.',
|
||||
html
|
||||
)
|
||||
|
||||
def test_handle_empty_values(self):
|
||||
bookmark = self.setup_bookmark()
|
||||
bookmark.title = ''
|
||||
bookmark.description = ''
|
||||
bookmark.website_title = None
|
||||
bookmark.website_description = None
|
||||
bookmark.save()
|
||||
exporter.export_netscape_html([bookmark])
|
Loading…
Reference in a new issue