summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2018-06-10 12:50:52 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2018-06-10 21:08:21 +0900
commit0edcae1ff875c64e7d011604df26fdb4a4dffca3 (patch)
tree0eb68670d6ade7a8e4492fa1a477f7c07153080f
parentac9f973c9be70c9f253a42939a73035be1e9e6aa (diff)
downloadsphinx-git-0edcae1ff875c64e7d011604df26fdb4a4dffca3.tar.gz
Fix #5019: autodoc: crashed by Form Feed Character
-rw-r--r--CHANGES1
-rw-r--r--sphinx/pycode/parser.py7
-rw-r--r--tests/test_pycode_parser.py9
3 files changed, 16 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index 9c48d472c..db36f5d81 100644
--- a/CHANGES
+++ b/CHANGES
@@ -26,6 +26,7 @@ Bugs fixed
* C++, fix lookup of full template specializations with no template arguments.
* #4667: C++, fix assertion on missing references in global scope when using
intersphinx. Thanks to Alan M. Carroll.
+* #5019: autodoc: crashed by Form Feed Character
Testing
--------
diff --git a/sphinx/pycode/parser.py b/sphinx/pycode/parser.py
index 5c4291d3d..40334f2e3 100644
--- a/sphinx/pycode/parser.py
+++ b/sphinx/pycode/parser.py
@@ -34,6 +34,11 @@ else:
ASSIGN_NODES = (ast.Assign)
+def filter_whitespace(code):
+ # type: (unicode) -> unicode
+ return code.replace('\f', ' ') # replace FF (form feed) with whitespace
+
+
def get_assign_targets(node):
# type: (ast.AST) -> List[ast.expr]
"""Get list of targets from Assign and AnnAssign node."""
@@ -466,7 +471,7 @@ class Parser(object):
def __init__(self, code, encoding='utf-8'):
# type: (unicode, unicode) -> None
- self.code = code
+ self.code = filter_whitespace(code)
self.encoding = encoding
self.comments = {} # type: Dict[Tuple[unicode, unicode], unicode]
self.deforders = {} # type: Dict[unicode, int]
diff --git a/tests/test_pycode_parser.py b/tests/test_pycode_parser.py
index 29363e17e..0875329a4 100644
--- a/tests/test_pycode_parser.py
+++ b/tests/test_pycode_parser.py
@@ -315,3 +315,12 @@ def test_decorators():
'func3': ('def', 7, 9),
'Foo': ('class', 11, 15),
'Foo.method': ('def', 13, 15)}
+
+
+def test_formfeed_char():
+ source = ('class Foo:\n'
+ '\f\n'
+ ' attr = 1234 #: comment\n')
+ parser = Parser(source)
+ parser.parse()
+ assert parser.comments == {('Foo', 'attr'): 'comment'}