diff --git a/CHANGES b/CHANGES index 65d237fc6..e8ee9e4d0 100644 --- a/CHANGES +++ b/CHANGES @@ -34,6 +34,7 @@ Bugs fixed :file:`parskip.sty` * #5958: versionadded directive causes crash with Python 3.5.0 * #5995: autodoc: autodoc_mock_imports conflict with metaclass on Python 3.7 +* #5871: texinfo: a section title ``.`` is not allowed Testing -------- diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py index d7490a652..63c7d2af8 100644 --- a/sphinx/writers/texinfo.py +++ b/sphinx/writers/texinfo.py @@ -384,9 +384,12 @@ class TexinfoTranslator(nodes.NodeVisitor): def escape_id(self, s): # type: (unicode) -> unicode """Return an escaped string suitable for node names and anchors.""" - bad_chars = ',:.()' + bad_chars = ',:()' for bc in bad_chars: s = s.replace(bc, ' ') + if re.search('[^ .]', s): + # remove DOTs if name contains other characters + s = s.replace('.', ' ') s = ' '.join(s.split()).strip() return self.escape(s) diff --git a/tests/test_build_texinfo.py b/tests/test_build_texinfo.py index d7b7e520a..93e10d758 100644 --- a/tests/test_build_texinfo.py +++ b/tests/test_build_texinfo.py @@ -15,10 +15,12 @@ import re from subprocess import Popen, PIPE import pytest +from mock import Mock from six import PY3 from test_build_html import ENV_WARNINGS from sphinx.testing.util import remove_unicode_literals, strip_escseq +from sphinx.util.docutils import new_document from sphinx.writers.texinfo import TexinfoTranslator @@ -93,3 +95,20 @@ def test_texinfo_citation(app, status, warning): 'This is a citation\n') in output assert ('@anchor{index cite2}@anchor{2}@w{(CITE2)} \n' 'This is a multiline citation\n') in output + + +@pytest.mark.sphinx('texinfo') +def test_texinfo_escape_id(app, status, warning): + settings = Mock(title='', + texinfo_dir_entry='', + texinfo_elements={}) + document = new_document('', settings) + translator = app.builder.create_translator(document, app.builder) + + assert translator.escape_id('Hello world') == 'Hello world' + assert translator.escape_id('Hello world') == 'Hello world' + assert translator.escape_id('Hello Sphinx world') == 'Hello Sphinx world' + assert translator.escape_id('Hello:world') == 'Hello world' + assert translator.escape_id('Hello(world)') == 'Hello world' + assert translator.escape_id('Hello world.') == 'Hello world' + assert translator.escape_id('.') == '.'