Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: parse_json also including html in titles #5970

Merged
merged 1 commit into from
Jul 22, 2019
Merged
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
2 changes: 1 addition & 1 deletion readthedocs/rtd_tests/files/api.fjson

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions readthedocs/rtd_tests/tests/test_search_json_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def test_h2_parsing(self):
)
self.assertEqual(data['path'], 'api')
self.assertEqual(data['sections'][1]['id'], 'a-basic-api-client-using-slumber')

# In api.fjson, title is in the form: A basic API client ``using slumber``
self.assertEqual(data['sections'][1]['title'], 'A basic API client using slumber')
Copy link
Member

Choose a reason for hiding this comment

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

In my test the quotes will still be there:

>>> pyquery.PyQuery('A basic API client ``using slumber``').text().replace('¶', '').strip()
'A basic API client ``using slumber``'
>>> 

Copy link
Member Author

Choose a reason for hiding this comment

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

When a text like this: Include ``404`` page is converted to html by sphinx. It is something like this: Include <code class=\"docutils literal notranslate\"><span class=\"pre\">404</span></code> page.

We were indexing this line as it is, because of which -- we are getting results with the html code - http://docs.celeryproject.org/en/latest/search.html?q=utilities&check_keywords=yes&area=default

It is something like this:

>>> import pyquery
>>> temp = 'Include <code class=\"docutils literal notranslate\"><span class=\"pre\">404</span></code> page'
>>> pyquery.PyQuery(temp).text().replace('¶', '').strip()
'Include 404 page' 

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for clarifying this!

self.assertTrue(data['sections'][1]['content'].startswith(
'You can use Slumber'
))
Expand Down
3 changes: 1 addition & 2 deletions readthedocs/search/parse_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def process_file(fjson_filename):

if 'title' in data:
title = data['title']
if title.startswith('<'):
title = PyQuery(data['title']).text()
title = PyQuery(data['title']).text().replace('¶', '').strip()
else:
log.info('Unable to index title for: %s', fjson_filename)

Expand Down