Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions pelican/plugins/search/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,15 @@ def get_input_files(
page.save_as if self._index_output() else page.relative_source_path
)
# Escape double-quotation marks in the title
title = striptags(page.title).replace('"', '\\"')
title = "".join(
c if c.isprintable() else " "
for c in striptags(page.title).replace('"', '\\"')
)
input_files.append(
{
"path": page_to_index,
"url": f"/{page.url}",
"title": f"{title}",
"title": title,
}
)

Expand Down
23 changes: 23 additions & 0 deletions tests/test_search_settings_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,26 @@ def test_template_pages_collected(
"title": "",
},
]

@pytest.mark.parametrize("non_printable", ["\u00a0", "\u200B", "\uFEFF"])
def test_unicode_non_printable_chars_stripped(self, non_printable):
"""Non printable chars should be all converted to a standard space"""
generator = SearchSettingsGenerator(
context={
"pages": [
self.PageArticleMock(f"title with nbsp{non_printable}char")
],
"articles": [],
},
settings={"TEMPLATE_PAGES": []},
path=None,
theme=None,
output_path="output",
)
assert generator.get_input_files() == [
{
"path": "save_as",
"url": "/url",
"title": "title with nbsp char",
}
]