Compare commits
6 Commits
test-docke
...
nginx-utf8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2248369777 | ||
|
|
ab57467944 | ||
|
|
7f7829bd4e | ||
|
|
b50cddc772 | ||
|
|
71bc3e071f | ||
|
|
e74505968b |
@@ -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 []
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
# This configuration file is saved with valid UTF-8 encoding,
|
||||
# including some CJK alphabets.
|
||||
|
||||
server {
|
||||
# 안녕하세요. 80번 포트에서 요청을 기다린다.
|
||||
# こんにちは。80番ポートからリクエストを待つ。
|
||||
# 你好。等待端口80上的请求。
|
||||
listen 80;
|
||||
}
|
||||
Reference in New Issue
Block a user