Skip to content

Commit

Permalink
Fix behavior with respect to forbidden characters
Browse files Browse the repository at this point in the history
  • Loading branch information
gnossen committed Sep 14, 2018
1 parent 7ebd4d0 commit 58c8ca7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyhocon/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def include_config(instring, loc, token):
# line1 \
# line2 \
# so a backslash precedes the \n
unquoted_string = Regex('(?:[^"\[\{\s\]\}#,=\$\\\\]|\\\\.)+[ \t]*', re.UNICODE).setParseAction(unescape_string)
unquoted_string = Regex('(?:[^^`+?!@*&"\[\{\s\]\}#,=\$\\\\]|\\\\.)+[ \t]*', re.UNICODE).setParseAction(unescape_string)
substitution_expr = Regex('[ \t]*\$\{[^\}]+\}[ \t]*').setParseAction(create_substitution)
string_expr = multiline_string | quoted_string | unquoted_string

Expand Down
2 changes: 1 addition & 1 deletion samples/aws.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
data-center-east = ${data-center-generic} { name = "east" }

// list merge
default-jvm-opts = [-XX:+UseParNewGC]
default-jvm-opts = ["-XX:+UseParNewGC"]
large-jvm-opts = ${default-jvm-opts} [-Xm16g]
}
10 changes: 5 additions & 5 deletions tests/test_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import mock
import tempfile
from collections import OrderedDict
from pyparsing import ParseSyntaxException, ParseException
from pyparsing import ParseSyntaxException, ParseException, ParseBaseException
import pytest
from pyhocon import ConfigFactory, ConfigSubstitutionException, ConfigTree, ConfigParser
from pyhocon.exceptions import ConfigMissingException, ConfigWrongTypeException, ConfigException
Expand Down Expand Up @@ -52,7 +52,7 @@ def test_parse_simple_value(self):

@pytest.mark.parametrize('forbidden_char', ['+', '`', '^', '?', '!', '@', '*', '&'])
def test_fail_parse_forbidden_characters(self, forbidden_char):
with pytest.raises(ParseSyntaxException):
with pytest.raises(ParseBaseException):
config = ConfigFactory.parse_string('a: hey man{}'.format(forbidden_char))

@pytest.mark.parametrize('forbidden_char', ['$', '"'])
Expand Down Expand Up @@ -602,8 +602,8 @@ def test_substitution_list_with_append(self):
config = ConfigFactory.parse_string(
"""
application.foo = 128m
application.large-jvm-opts = [-XX:+UseParNewGC] [-Xm16g, ${application.foo}]
application.large-jvm-opts2 = [-Xm16g, ${application.foo}] [-XX:+UseParNewGC]
application.large-jvm-opts = ["-XX:+UseParNewGC"] [-Xm16g, ${application.foo}]
application.large-jvm-opts2 = [-Xm16g, ${application.foo}] ["-XX:+UseParNewGC"]
""")

assert config["application.large-jvm-opts"] == [
Expand All @@ -622,7 +622,7 @@ def test_substitution_list_with_append_substitution(self):
config = ConfigFactory.parse_string(
"""
application.foo = 128m
application.default-jvm-opts = [-XX:+UseParNewGC]
application.default-jvm-opts = ["-XX:+UseParNewGC"]
application.large-jvm-opts = ${application.default-jvm-opts} [-Xm16g, ${application.foo}]
application.large-jvm-opts2 = [-Xm16g, ${application.foo}] ${application.default-jvm-opts}
""")
Expand Down

0 comments on commit 58c8ca7

Please sign in to comment.