Skip to content

Commit 92eef1b

Browse files
committed
Set the default encoding to utf-8-sig to handle files with a
UTF-8 BOM correctly.
1 parent 8e574c4 commit 92eef1b

File tree

7 files changed

+16
-4
lines changed

7 files changed

+16
-4
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Release 0.6.2 (in development)
22
==============================
33

4+
* Set the default encoding to ``utf-8-sig`` to handle files with a
5+
UTF-8 BOM correctly.
6+
47
* #178: apply ``add_function_parentheses`` config value to C
58
functions as promised.
69

doc/config.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ General configuration
7777
.. confval:: source_encoding
7878

7979
The encoding of all reST source files. The recommended encoding, and the
80-
default value, is ``'utf-8'``.
80+
default value, is ``'utf-8-sig'``.
8181

8282
.. versionadded:: 0.5
8383
Previously, Sphinx accepted only UTF-8 encoded sources.

sphinx/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Config(object):
3737

3838
master_doc = ('contents', 'env'),
3939
source_suffix = ('.rst', 'env'),
40-
source_encoding = ('utf-8', 'env'),
40+
source_encoding = ('utf-8-sig', 'env'),
4141
unused_docs = ([], 'env'),
4242
exclude_dirs = ([], 'env'),
4343
exclude_trees = ([], 'env'),

sphinx/environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
'cloak_email_addresses': True,
5353
'pep_base_url': 'http://www.python.org/dev/peps/',
5454
'rfc_base_url': 'http://tools.ietf.org/html/',
55-
'input_encoding': 'utf-8',
55+
'input_encoding': 'utf-8-sig',
5656
'doctitle_xform': False,
5757
'sectsubtitle_xform': False,
5858
}

tests/root/bom.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
File with UTF-8 BOM
2+
===================
3+
4+
This file has a UTF-8 "BOM".
5+

tests/root/contents.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Contents:
1717
includes
1818
markup
1919
desc
20+
bom
2021
math
2122
autodoc
2223
autosummary

tests/test_build.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def teardown_module():
4141
%(root)s/images.txt:9: WARNING: image file not readable: foo.png
4242
%(root)s/images.txt:23: WARNING: nonlocal image URI found: \
4343
http://www.python.org/logo.png
44-
%(root)s/includes.txt:: (WARNING/2) Encoding 'utf-8' used for reading \
44+
%(root)s/includes.txt:: (WARNING/2) Encoding 'utf-8-sig' used for reading \
4545
included file u'wrongenc.inc' seems to be wrong, try giving an :encoding: option
4646
%(root)s/includes.txt:56: WARNING: download file not readable: nonexisting.png
4747
"""
@@ -115,6 +115,9 @@ def teardown_module():
115115
".//div[@class='footer']": 'Georg Brandl & Team',
116116
".//a[@href='http://python.org/']": '',
117117
},
118+
'bom.html': {
119+
".//title": " File with UTF-8 BOM",
120+
},
118121
'_static/statictmpl.html': {
119122
".//project": 'Sphinx <Tests>',
120123
},

0 commit comments

Comments
 (0)