Skip to content
Open
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
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Contributors
* Steve Piercy -- documentation improvements
* Szymon Karpinski -- intersphinx improvements
* \T. Powers -- HTML output improvements
* Taiki Ohno -- bug fixes in search results
* Taku Shimizu -- epub3 builder
* Tamika Nomara -- bug fixes
* Thomas Lamb -- linkcheck builder
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ Bugs fixed
* #14004: Fix :confval:`autodoc_type_aliases` when they appear in PEP 604
union syntax (``Alias | Type``).
Patch by Tamika Nomara.
* #14028: Fix the encoding of URLs in search results.
Patch by Taiki Ohno.


Testing
Expand Down
3 changes: 2 additions & 1 deletion sphinx/themes/basic/static/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ const _displayItem = (item, searchTerms, highlightTerms) => {
linkUrl = docName + docLinkSuffix;
}
let linkEl = listItem.appendChild(document.createElement("a"));
linkEl.href = linkUrl + anchor;
const encodedLinkUrl = linkUrl.split("/").map(encodeURIComponent).join("/");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for linkUrl to contain other components that we would not want to URL-encode? (for example, protocol scheme - http://, or similar?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comment.

If linkUrl contains something like http://, the colon would be encoded to %3A, so it would become http%3A//.
At least in the examples shown in the related issue, it doesn’t seem to contain any protocol scheme.

I’m checking the behavior of linkUrl, but if you know of any cases where it may contain a protocol scheme, please let me know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @hntk03 - I think in particular it is the behaviour and values of the content_root setting that we should inspect for this.

Currently I don't think that it could contain a URL scheme -- however perhaps we should write this part of the code defensively even so (because this JavaScript code may exist and run for a long duration of time in various documentation contexts).

cc @AA-Turner (in case you can add any more thoughts about the content_root, re: 8e730ae)

linkEl.href = encodedLinkUrl + anchor;
linkEl.dataset.score = score;
linkEl.innerHTML = title;
if (descr) {
Expand Down
Loading