summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES2
-rw-r--r--sphinx/search.py4
-rw-r--r--tests/test_autosummary.py2
-rw-r--r--tests/test_search.py39
4 files changed, 45 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index fecb13024..b3e775b53 100644
--- a/CHANGES
+++ b/CHANGES
@@ -17,6 +17,8 @@ Release 1.0 (in development)
Release 0.6.2 (in development)
==============================
+* Don't consider contents of source comments for the search index.
+
* Set the default encoding to ``utf-8-sig`` to handle files with a
UTF-8 BOM correctly.
diff --git a/sphinx/search.py b/sphinx/search.py
index 8bde13266..499c4aa9e 100644
--- a/sphinx/search.py
+++ b/sphinx/search.py
@@ -12,7 +12,7 @@ import re
import cPickle as pickle
from cStringIO import StringIO
-from docutils.nodes import Text, NodeVisitor
+from docutils.nodes import comment, Text, NodeVisitor, SkipNode
from sphinx.util import jsdump, rpartition
try:
@@ -97,6 +97,8 @@ class WordCollector(NodeVisitor):
self.found_words = []
def dispatch_visit(self, node):
+ if node.__class__ is comment:
+ raise SkipNode
if node.__class__ is Text:
self.found_words.extend(word_re.findall(node.astext()))
diff --git a/tests/test_autosummary.py b/tests/test_autosummary.py
index d39131791..276b93557 100644
--- a/tests/test_autosummary.py
+++ b/tests/test_autosummary.py
@@ -22,7 +22,7 @@ def test_mangle_signature():
(a, b, c, d, e) :: (a, b, c, d, e)
(a, b, c=1, d=2, e=3) :: (a, b[, c, d, e])
(a, b, aaa=1, bbb=1, ccc=1, eee=1, fff=1, ggg=1, hhh=1, iii=1, jjj=1)\
- :: (a, b[, aaa, bbb, ccc, eee, fff, ...])
+ :: (a, b[, aaa, bbb, ccc, ...])
(a, b, c=(), d=<foo>) :: (a, b[, c, d])
(a, b, c='foobar()', d=123) :: (a, b[, c, d])
"""
diff --git a/tests/test_search.py b/tests/test_search.py
new file mode 100644
index 000000000..3dd043bc7
--- /dev/null
+++ b/tests/test_search.py
@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+"""
+ test_search
+ ~~~~~~~~~~~
+
+ Test the search index builder.
+
+ :copyright: Copyright 2007-2009 by the Sphinx team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+from docutils import frontend, utils, nodes
+from docutils.parsers import rst
+
+from sphinx.search import IndexBuilder
+
+
+def setup_module():
+ global settings, parser
+ optparser = frontend.OptionParser(components=(rst.Parser,))
+ settings = optparser.get_default_values()
+ parser = rst.Parser()
+
+
+FILE_CONTENTS = '''\
+.. test that comments are not indexed: boson
+
+test that non-comments are indexed: fermion
+'''
+
+def test_wordcollector():
+ doc = utils.new_document('test data', settings)
+ doc['file'] = 'dummy'
+ parser.parse(FILE_CONTENTS, doc)
+
+ ix = IndexBuilder(None)
+ ix.feed('filename', 'title', doc)
+ assert 'boson' not in ix._mapping
+ assert 'fermion' in ix._mapping