Skip to content

Commit

Permalink
Merge pull request from GHSA-9v45-336h-5xw5
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd authored Jan 15, 2024
1 parent 4db4bd8 commit 33989f1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
28 changes: 28 additions & 0 deletions public/_/readthedocs-search.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,34 @@
"version": {
"slug": "stable"
}
},
{
"blocks": [
{
"content": "Test content for <strong>XSS</strong>",
"highlights": {
"content": [],
"title": []
},
"id": "deleting-offline-formats",
"title": "Test title for <strong>XSS</strong>",
"type": "section"
}
],
"domain": "https://docs.readthedocs.io",
"highlights": {
"title": []
},
"path": "/en/stable/<strong>XSS</strong>.html",
"project": {
"alias": null,
"slug": "docs"
},
"title": "Test for <strong>XSS</strong>",
"type": "page",
"version": {
"slug": "stable"
}
}
]
}
16 changes: 8 additions & 8 deletions src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,23 +241,23 @@ export class SearchElement extends LitElement {
}

renderBlockResult(block, index, result) {
// TODO: distinguish between `block.type` (section or domain)

// TODO: take a substring of the title as well in case it's too long?
let title = block.title;
if (block.highlights.title.length) {
title = block.highlights.title[0];
title = unsafeHTML(block.highlights.title[0]);
}

let content = block.content.substring(0, MAX_SUBSTRING_LIMIT) + " ...";
if (block.highlights.content.length) {
// TODO: with this logic it could happen the highlighted part is outside of the substring
content = block.highlights.content[0];
if (content.length > MAX_SUBSTRING_LIMIT) {
content =
content = unsafeHTML(
"... " +
block.highlights.content[0].substring(0, MAX_SUBSTRING_LIMIT) +
" ...";
" ..."
);
} else {
content = unsafeHTML(block.highlights.content[0]);
}
}

Expand All @@ -268,8 +268,8 @@ export class SearchElement extends LitElement {
href="${result.path}#${block.id}"
>
<div id="hit-${index}">
<p class="hit subheading">${unsafeHTML(title)}</p>
<p class="hit content">${unsafeHTML(content)}</p>
<p class="hit subheading">${title}</p>
<p class="hit content">${content}</p>
</div>
</a>
`;
Expand Down

0 comments on commit 33989f1

Please sign in to comment.