Skip to content

Commit 756e6e7

Browse files
authored
Merge pull request #2754 from rtfd/bugfix-bundle
This merges all the bugfix PR's I had into one.
2 parents 340ea0e + f5db85c commit 756e6e7

File tree

9 files changed

+75
-38
lines changed

9 files changed

+75
-38
lines changed

media/javascript/rtd.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@
6767
}
6868
);
6969

70-
checkVersion(slug, version);
70+
// This is a deprecated API and file, so removing this to reduce errors
71+
// on our servers.
72+
// checkVersion(slug, version);
7173
getVersions(slug, version);
7274

7375
/*
@@ -78,12 +80,12 @@
7880
*/
7981

8082

81-
$.ajax({
82-
url: "https://api.grokthedocs.com/static/javascript/bundle-client.js",
83-
crossDomain: true,
84-
dataType: "script",
85-
cache: true,
86-
});
83+
// $.ajax({
84+
// url: "https://api.grokthedocs.com/static/javascript/bundle-client.js",
85+
// crossDomain: true,
86+
// dataType: "script",
87+
// cache: true,
88+
// });
8789

8890

8991

readthedocs/core/resolver.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ def base_resolve_path(self, project_slug, filename, version_slug=None,
5656
# Only support `/docs/project' URLs outside our normal environment. Normally
5757
# the path should always have a subdomain or CNAME domain
5858
if subdomain or cname or (self._use_subdomain()):
59-
url = '/'
59+
url = u'/'
6060
else:
61-
url = '/docs/{project_slug}/'
61+
url = u'/docs/{project_slug}/'
6262

6363
if subproject_slug:
64-
url += 'projects/{subproject_slug}/'
64+
url += u'projects/{subproject_slug}/'
6565

6666
if single_version:
67-
url += '{filename}'
67+
url += u'{filename}'
6868
else:
69-
url += '{language}/{version_slug}/{filename}'
69+
url += u'{language}/{version_slug}/{filename}'
7070

7171
return url.format(
7272
project_slug=project_slug, filename=filename,

readthedocs/core/signals.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def decide_if_cors(sender, request, **kwargs):
2626
2727
Returns True when a request should be given CORS access.
2828
"""
29+
if 'HTTP_ORIGIN' not in request.META:
30+
return False
2931
host = urlparse(request.META['HTTP_ORIGIN']).netloc.split(':')[0]
3032
valid_url = False
3133
for url in WHITELIST_URLS:

readthedocs/oauth/services/bitbucket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,5 +214,5 @@ def setup_webhook(self, project):
214214
log.error('Bitbucket webhook creation failed for project: %s',
215215
project)
216216
log.debug('Bitbucket webhook creation failure response: %s',
217-
dict(resp))
217+
resp.content)
218218
return (False, resp)

readthedocs/oauth/services/github.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def setup_webhook(self, project):
205205
log.error('GitHub webhook creation failed for project: %s',
206206
project)
207207
log.debug('GitHub webhook creation failure response: %s',
208-
dict(resp))
208+
resp.content)
209209
return (False, resp)
210210

211211
@classmethod

readthedocs/projects/version_handling.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Project version handling"""
22

3+
import unicodedata
34
from collections import defaultdict
45
from packaging.version import Version
56
from packaging.version import InvalidVersion
@@ -107,8 +108,8 @@ def version_windows(versions, major=1, minor=1, point=1):
107108

108109
def parse_version_failsafe(version_string):
109110
try:
110-
return Version(version_string)
111-
except InvalidVersion:
111+
return Version(unicodedata.normalize('NFKD', version_string).encode('ascii', 'ignore'))
112+
except (UnicodeError, InvalidVersion):
112113
return None
113114

114115

readthedocs/restapi/views/model_views.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -132,27 +132,23 @@ def sync_versions(self, request, **kwargs):
132132
log.exception("Sync Versions Error: %s" % e.message)
133133
return Response({'error': e.message}, status=status.HTTP_400_BAD_REQUEST)
134134

135-
try:
136-
old_stable = project.get_stable_version()
137-
promoted_version = project.update_stable_version()
138-
if promoted_version:
139-
new_stable = project.get_stable_version()
140-
log.info(
141-
"Triggering new stable build: {project}:{version}".format(
142-
project=project.slug,
143-
version=new_stable.identifier))
144-
trigger_build(project=project, version=new_stable)
145-
146-
# Marking the tag that is considered the new stable version as
147-
# active and building it if it was just added.
148-
if (
149-
activate_new_stable and
150-
promoted_version.slug in added_versions):
151-
promoted_version.active = True
152-
promoted_version.save()
153-
trigger_build(project=project, version=promoted_version)
154-
except:
155-
log.exception("Stable Version Failure", exc_info=True)
135+
promoted_version = project.update_stable_version()
136+
if promoted_version:
137+
new_stable = project.get_stable_version()
138+
log.info(
139+
"Triggering new stable build: {project}:{version}".format(
140+
project=project.slug,
141+
version=new_stable.identifier))
142+
trigger_build(project=project, version=new_stable)
143+
144+
# Marking the tag that is considered the new stable version as
145+
# active and building it if it was just added.
146+
if (
147+
activate_new_stable and
148+
promoted_version.slug in added_versions):
149+
promoted_version.active = True
150+
promoted_version.save()
151+
trigger_build(project=project, version=promoted_version)
156152

157153
return Response({
158154
'added_versions': added_versions,

readthedocs/rtd_tests/tests/test_sync_versions.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
13
import json
24

35
from django.test import TestCase
@@ -344,3 +346,18 @@ def test_update_inactive_stable_version(self):
344346
version_stable = Version.objects.get(slug=STABLE)
345347
self.assertFalse(version_stable.active)
346348
self.assertEqual(version_stable.identifier, '1.0.0')
349+
350+
def test_unicode(self):
351+
version_post_data = {
352+
'branches': [],
353+
'tags': [
354+
{'identifier': 'foo-£', 'verbose_name': 'foo-£'},
355+
]
356+
}
357+
358+
resp = self.client.post(
359+
'/api/v2/project/%s/sync_versions/' % self.pip.pk,
360+
data=json.dumps(version_post_data),
361+
content_type='application/json',
362+
)
363+
self.assertEqual(resp.status_code, 200)

readthedocs/search/utils.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def process_mkdocs_json(version, build_dir=True):
2525
html_files.append(os.path.join(root, filename))
2626
page_list = []
2727
for filename in html_files:
28+
if not valid_mkdocs_json(file_path=filename):
29+
continue
2830
relative_path = parse_path_from_file(documentation_type='mkdocs', file_path=filename)
2931
html = parse_content_from_file(documentation_type='mkdocs', file_path=filename)
3032
headers = parse_headers_from_file(documentation_type='mkdocs', file_path=filename)
@@ -50,12 +52,29 @@ def recurse_while_none(element):
5052
return element.text
5153

5254

55+
def valid_mkdocs_json(file_path):
56+
try:
57+
with codecs.open(file_path, encoding='utf-8', mode='r') as f:
58+
content = f.read()
59+
except IOError as e:
60+
log.warning('(Search Index) Unable to index file: %s, error: %s' % (file_path, e))
61+
return None
62+
63+
page_json = json.loads(content)
64+
for to_check in ['url', 'content']:
65+
if to_check not in page_json:
66+
log.warning('(Search Index) Unable to index file: %s error: Invalid JSON' % (file_path))
67+
return None
68+
69+
return True
70+
71+
5372
def parse_path_from_file(documentation_type, file_path):
5473
try:
5574
with codecs.open(file_path, encoding='utf-8', mode='r') as f:
5675
content = f.read()
5776
except IOError as e:
58-
log.info('(Search Index) Unable to index file: %s, error :%s' % (file_path, e))
77+
log.warning('(Search Index) Unable to index file: %s, error: %s' % (file_path, e))
5978
return ''
6079

6180
page_json = json.loads(content)

0 commit comments

Comments
 (0)