Compare commits

...

6 Commits

Author SHA1 Message Date
Seth Schoen
2248369777 Fix lint problems with long lines 2019-01-30 15:12:55 -08:00
Seth Schoen
ab57467944 Merge https://github.com/g6123/certbot into nginx-utf8 2019-01-30 14:27:48 -08:00
ohemorange
7f7829bd4e Merge branch 'master' into master 2018-11-07 15:44:33 -08:00
cumul
b50cddc772 Added test for valid/invalid unicode characters 2018-10-31 16:48:01 +09:00
cumul
71bc3e071f Use io module instead of codecs
See https://mail.python.org/pipermail/python-list/2015-March/687124.html
2018-10-31 16:47:48 +09:00
cumul
e74505968b Use UTF-8 encoding for nginx plugin 2017-12-19 05:34:31 +09:00
4 changed files with 41 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
import copy
import functools
import glob
import io
import logging
import os
import pyparsing
@@ -203,12 +204,16 @@ class NginxParser(object):
if item in self.parsed and not override:
continue
try:
with open(item) as _file:
with io.open(item, "r", encoding="utf-8") as _file:
parsed = nginxparser.load(_file)
self.parsed[item] = parsed
trees.append(parsed)
except IOError:
logger.warning("Could not open file: %s", item)
except UnicodeDecodeError:
logger.warning("Could not read file: %s due to invalid "
"character. Only UTF-8 encoding is "
"supported.", item)
except pyparsing.ParseException as err:
logger.debug("Could not parse file: %s due to %s", item, err)
return trees
@@ -412,10 +417,13 @@ class NginxParser(object):
def _parse_ssl_options(ssl_options):
if ssl_options is not None:
try:
with open(ssl_options) as _file:
with io.open(ssl_options, "r", encoding="utf-8") as _file:
return nginxparser.load(_file)
except IOError:
logger.warning("Missing NGINX TLS options file: %s", ssl_options)
except UnicodeDecodeError:
logger.warn("Could not read file: %s due to invalid character. "
"Only UTF-8 encoding is supported.", ssl_options)
except pyparsing.ParseBaseException as err:
logger.debug("Could not parse file: %s due to %s", ssl_options, err)
return []

View File

@@ -450,6 +450,21 @@ class NginxParserTest(util.NginxTest): #pylint: disable=too-many-public-methods
self.assertEqual(len(default.raw), len(new_vhost_parsed.raw))
self.assertTrue(next(iter(default.addrs)).super_eq(next(iter(new_vhost_parsed.addrs))))
def test_valid_unicode_characters(self):
nparser = parser.NginxParser(self.config_path)
# pylint: disable=protected-access
path = nparser.abs_path('unicode_support/valid_unicode_comments.conf')
parsed = nparser._parse_files(path)
self.assertEqual(['server'], parsed[0][2][0])
self.assertEqual(['listen', '80'], parsed[0][2][1][3])
def test_invalid_unicode_characters(self):
nparser = parser.NginxParser(self.config_path)
# pylint: disable=protected-access
path = nparser.abs_path('unicode_support/invalid_unicode_comments.conf')
parsed = nparser._parse_files(path)
self.assertEqual([], parsed)
def test_duplicate_vhost_remove_ipv6only(self):
nparser = parser.NginxParser(self.config_path)

View File

@@ -0,0 +1,7 @@
# This configuration file is saved with EUC-KR (a.k.a. cp949) encoding,
# including some Korean alphabets.
server {
# <20>ȳ<EFBFBD><C8B3>ϼ<EFBFBD><CFBC><EFBFBD>. 80<38><30> <20><>Ʈ<EFBFBD><C6AE><EFBFBD><EFBFBD> <20><>û<EFBFBD><C3BB> <20><><EFBFBD>ٸ<EFBFBD><D9B8><EFBFBD>.
listen 80;
}

View File

@@ -0,0 +1,9 @@
# This configuration file is saved with valid UTF-8 encoding,
# including some CJK alphabets.
server {
# 안녕하세요. 80번 포트에서 요청을 기다린다.
# こんにちは。80番ポートからリクエストを待つ。
# 你好。等待端口80上的请求。
listen 80;
}