Skip to content

Commit

Permalink
Write 'searchindex.js' using minimal JSON separators (#13062)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
  • Loading branch information
jayaddison and AA-Turner authored Oct 24, 2024
1 parent 8042eb6 commit b75e695
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion sphinx/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ class _JavaScriptIndex:
SUFFIX = ')'

def dumps(self, data: Any) -> str:
return self.PREFIX + json.dumps(data, sort_keys=True) + self.SUFFIX
data_json = json.dumps(data, separators=(',', ':'), sort_keys=True)
return self.PREFIX + data_json + self.SUFFIX

def loads(self, s: str) -> Any:
data = s[len(self.PREFIX) : -len(self.SUFFIX)]
Expand Down
2 changes: 1 addition & 1 deletion tests/js/fixtures/cpp/searchindex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/js/fixtures/multiterm/searchindex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/js/fixtures/partial/searchindex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/js/fixtures/titles/searchindex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ def test_term_in_heading_and_section(app):
# if search term is in the title of one doc and in the text of another
# both documents should be a hit in the search index as a title,
# respectively text hit
assert '"textinhead": 2' in searchindex
assert '"textinhead": 0' in searchindex
assert '"textinhead":2' in searchindex
assert '"textinhead":0' in searchindex


@pytest.mark.sphinx('html', testroot='search')
Expand Down

0 comments on commit b75e695

Please sign in to comment.