Просмотр исходного кода

Sphinx: Specify encoding when opening files for title extraction

When the encoding is not specified, open() may choose an encoding
based on the locale in use. That encoding may have no relationship
to the encoding of the file being opened. Use the locale from the
document settings instead, which should better match the file's
encoding.

Fixes: #24679
Craig Scott 2 лет назад
Родитель
Сommit
f0d6010cb5
1 измененных файлов с 3 добавлено и 2 удалено
  1. 3 2
      Utilities/Sphinx/cmake.py

+ 3 - 2
Utilities/Sphinx/cmake.py

@@ -242,12 +242,13 @@ class CMakeTransform(Transform):
            The cmake --help-*-list commands also depend on this convention.
            Return the title or False if the document file does not exist.
         """
-        env = self.document.settings.env
+        settings = self.document.settings
+        env = settings.env
         title = self.titles.get(docname)
         if title is None:
             fname = os.path.join(env.srcdir, docname+'.rst')
             try:
-                f = open(fname, 'r')
+                f = open(fname, 'r', encoding=settings.input_encoding)
             except IOError:
                 title = False
             else: