From 87a0bf9d5e4b632028f21b31f5433d31df448ea4 Mon Sep 17 00:00:00 2001 From: "Brandon T. Willard" Date: Tue, 1 Jan 2019 21:38:14 -0600 Subject: [PATCH 1/4] Allow periods in texinfo node names Closes #5871. --- sphinx/writers/texinfo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py index d7490a652..fd0c244d3 100644 --- a/sphinx/writers/texinfo.py +++ b/sphinx/writers/texinfo.py @@ -384,7 +384,7 @@ 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, ' ') s = ' '.join(s.split()).strip() From 133ed17de621b41ab62d02bb5d7e82132f6a369c Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 3 Feb 2019 18:41:07 +0900 Subject: [PATCH 2/4] Add testcase for TexinfoTranslator.escape_id() --- tests/test_build_texinfo.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_build_texinfo.py b/tests/test_build_texinfo.py index d7b7e520a..a1987689b 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('.') == '.' From e483e4afc33ce4e06de5ceec644c1b1e5a9db3b6 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 3 Feb 2019 18:51:19 +0900 Subject: [PATCH 3/4] texinfo: remove DOTs from name if name contains other characters --- sphinx/writers/texinfo.py | 3 +++ tests/test_build_texinfo.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py index fd0c244d3..63c7d2af8 100644 --- a/sphinx/writers/texinfo.py +++ b/sphinx/writers/texinfo.py @@ -387,6 +387,9 @@ class TexinfoTranslator(nodes.NodeVisitor): 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 a1987689b..93e10d758 100644 --- a/tests/test_build_texinfo.py +++ b/tests/test_build_texinfo.py @@ -110,5 +110,5 @@ def test_texinfo_escape_id(app, status, warning): 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('Hello world.') == 'Hello world' assert translator.escape_id('.') == '.' From 0bb5aa82619846d7eeb214bf09dec7b93ebeccfa Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 3 Feb 2019 18:55:23 +0900 Subject: [PATCH 4/4] Update CHANGES for PR #5872 --- CHANGES | 1 + 1 file changed, 1 insertion(+) 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 --------