Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: mozilla/kuma
...
head fork: mozilla/kuma
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 2 contributors
View
15 apps/wiki/content.py
@@ -46,18 +46,21 @@ def parse(src):
return ContentSectionTool(src)
-def get_content_sections(src = ''):
+def get_content_sections(src=''):
"""Gets sections in a document, """
sections = []
if src:
attr = '[id]'
- elements = pq(src).find(((attr + ',').join(SECTION_TAGS)) + attr)
-
- def objectify_pyquery_item(i):
- sections.append({ 'title': i.text(), 'id': i.attr('id') })
+ try:
+ elements = pq(src).find(((attr + ',').join(SECTION_TAGS)) + attr)
+
+ def objectify_pyquery_item(i):
+ sections.append({'title': i.text(), 'id': i.attr('id')})
- elements.each(lambda e: objectify_pyquery_item(e))
+ elements.each(lambda e: objectify_pyquery_item(e))
+ except:
+ pass
return sections
View
8 apps/wiki/tests/test_content.py
@@ -15,7 +15,7 @@
from wiki.content import (CodeSyntaxFilter, DekiscriptMacroFilter,
SectionTOCFilter, SectionIDFilter, IframeHostFilter,
H2TOCFilter, H3TOCFilter,
- SECTION_TAGS, get_seo_description)
+ SECTION_TAGS, get_seo_description, get_content_sections)
from wiki.models import ALLOWED_TAGS, ALLOWED_ATTRIBUTES, Document
from wiki.tests import normalize_html, doc_rev, document, revision
from wiki.helpers import bugize_text
@@ -24,6 +24,12 @@
class ContentSectionToolTests(TestCase):
fixtures = ['test_users.json']
+ def test_section_pars_for_empty_docs(self):
+ doc = document(title='Doc', locale=u'fr', slug=u'doc', save=True,
+ html='<!-- -->')
+ res = get_content_sections(doc.html)
+ eq_(type(res).__name__, 'list')
+
def test_section_ids(self):
doc_src = """
View
2  apps/wiki/views.py
@@ -311,7 +311,7 @@ def _get_document_for_json(doc, addLocaleToTitle=False):
else:
review_tags = [x.name for x in
doc.current_revision.review_tags.all()]
-
+
return {
'title': title,
'label': doc.title,

No commit comments for this range

Something went wrong with that request. Please try again.