Repository: sphinx-doc/sphinx

Issue:
qthelp_namespace doesn't allow dashes
When setting the qthelp_namespace variable to a reverse URL with a dash the dash is removed. For example Qt uses ``org.qt-project.qtbluetooth.5110`` as Namespace which would not be possible with the qthelp Builder because it would be changed to ``org.qtproject.qtbluetooth.5110``.

I think namespaces should at least allow a reverse URL.

This code in ``sphinx.builders.qthelp`` tries to clean the namespace:

    nspace = re.sub('[^a-zA-Z0-9.]', '', nspace)
    nspace = re.sub(r'\.+', '.', nspace).strip('.')
    nspace = nspace.lower()

Discussion:

Patch:
diff --git a/CHANGES b/CHANGES
index 6ce5f856f..ada67e572 100644
--- a/CHANGES
+++ b/CHANGES
@@ -38,6 +38,7 @@ Incompatible changes
 * Modifying a template variable ``script_files`` in templates is allowed now.
   Please use ``app.add_js_file()`` instead.
 * #5072: Save environment object also with only new documents
+* #5035: qthelp builder allows dashes in :confval:`qthelp_namespace`
 
 Deprecated
 ----------
diff --git a/sphinx/builders/qthelp.py b/sphinx/builders/qthelp.py
index 9afe47637..a40cb2709 100644
--- a/sphinx/builders/qthelp.py
+++ b/sphinx/builders/qthelp.py
@@ -140,7 +140,7 @@ def istoctree(node):
         else:
             nspace = 'org.sphinx.%s.%s' % (outname, self.config.version)
 
-        nspace = re.sub('[^a-zA-Z0-9.]', '', nspace)
+        nspace = re.sub('[^a-zA-Z0-9.\-]', '', nspace)
         nspace = re.sub(r'\.+', '.', nspace).strip('.')
         nspace = nspace.lower()
 


Test patch:
diff --git a/tests/test_build_qthelp.py b/tests/test_build_qthelp.py
index a0d4fcf2a..f427ec2d8 100644
--- a/tests/test_build_qthelp.py
+++ b/tests/test_build_qthelp.py
@@ -88,11 +88,11 @@ def test_qthelp_namespace(app, status, warning):
     app.builder.build_all()
 
     qhp = (app.outdir / 'Python.qhp').text()
-    assert '<namespace>org.sphinxdoc.sphinx</namespace>' in qhp
+    assert '<namespace>org.sphinx-doc.sphinx</namespace>' in qhp
 
     qhcp = (app.outdir / 'Python.qhcp').text()
-    assert '<homePage>qthelp://org.sphinxdoc.sphinx/doc/index.html</homePage>' in qhcp
-    assert '<startPage>qthelp://org.sphinxdoc.sphinx/doc/index.html</startPage>' in qhcp
+    assert '<homePage>qthelp://org.sphinx-doc.sphinx/doc/index.html</homePage>' in qhcp
+    assert '<startPage>qthelp://org.sphinx-doc.sphinx/doc/index.html</startPage>' in qhcp
 
 
 @pytest.mark.sphinx('qthelp', testroot='basic')