mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-22 10:19:57 +00:00
handle quoted control sequences correctly
This commit is contained in:
@ -68,6 +68,20 @@ def test_parse_array_comment() -> None:
|
||||
])]
|
||||
|
||||
|
||||
def test_parse_array_quotes() -> None:
|
||||
"""
|
||||
must correctly process quoted brackets
|
||||
"""
|
||||
parser = PkgbuildParser(StringIO("""var=(first "(" second)"""))
|
||||
assert list(parser.parse()) == [PkgbuildPatch("var", ["first", "(", "second"])]
|
||||
|
||||
parser = PkgbuildParser(StringIO("""var=(first ")" second)"""))
|
||||
assert list(parser.parse()) == [PkgbuildPatch("var", ["first", ")", "second"])]
|
||||
|
||||
parser = PkgbuildParser(StringIO("""var=(first ')' second)"""))
|
||||
assert list(parser.parse()) == [PkgbuildPatch("var", ["first", ")", "second"])]
|
||||
|
||||
|
||||
def test_parse_array_exception() -> None:
|
||||
"""
|
||||
must raise exception if there is no closing bracket
|
||||
@ -109,6 +123,26 @@ def test_parse_function_inner_shell() -> None:
|
||||
assert list(parser.parse()) == [PkgbuildPatch("var()", "{ { echo hello world } }")]
|
||||
|
||||
|
||||
def test_parse_function_quotes() -> None:
|
||||
"""
|
||||
must parse function with bracket in quotes
|
||||
"""
|
||||
parser = PkgbuildParser(StringIO("""var ( ) { echo "hello world {" } """))
|
||||
assert list(parser.parse()) == [PkgbuildPatch("var()", """{ echo "hello world {" }""")]
|
||||
|
||||
parser = PkgbuildParser(StringIO("""var ( ) { echo hello world "{" } """))
|
||||
assert list(parser.parse()) == [PkgbuildPatch("var()", """{ echo hello world "{" }""")]
|
||||
|
||||
parser = PkgbuildParser(StringIO("""var ( ) { echo "hello world }" } """))
|
||||
assert list(parser.parse()) == [PkgbuildPatch("var()", """{ echo "hello world }" }""")]
|
||||
|
||||
parser = PkgbuildParser(StringIO("""var ( ) { echo hello world "}" } """))
|
||||
assert list(parser.parse()) == [PkgbuildPatch("var()", """{ echo hello world "}" }""")]
|
||||
|
||||
parser = PkgbuildParser(StringIO("""var ( ) { echo hello world '}' } """))
|
||||
assert list(parser.parse()) == [PkgbuildPatch("var()", """{ echo hello world '}' }""")]
|
||||
|
||||
|
||||
def test_parse_function_exception() -> None:
|
||||
"""
|
||||
must raise exception if no bracket found
|
||||
@ -176,6 +210,10 @@ def test_parse(resource_path_root: Path) -> None:
|
||||
PkgbuildPatch("array", ["first", "1suffix", "2suffix", "last"]),
|
||||
PkgbuildPatch("array", ["first", "prefix1", "prefix2", "last"]),
|
||||
PkgbuildPatch("array", ["first", "prefix1suffix", "prefix2suffix", "last"]),
|
||||
PkgbuildPatch("array", ["first", "(", "second"]),
|
||||
PkgbuildPatch("array", ["first", ")", "second"]),
|
||||
PkgbuildPatch("array", ["first", "(", "second"]),
|
||||
PkgbuildPatch("array", ["first", ")", "second"]),
|
||||
PkgbuildPatch("function()", """{ single line }"""),
|
||||
PkgbuildPatch("function()", """{
|
||||
multi
|
||||
@ -202,5 +240,17 @@ def test_parse(resource_path_root: Path) -> None:
|
||||
first
|
||||
{ inner shell }
|
||||
last
|
||||
}"""),
|
||||
PkgbuildPatch("function()", """{
|
||||
body "{" argument
|
||||
}"""),
|
||||
PkgbuildPatch("function()", """{
|
||||
body "}" argument
|
||||
}"""),
|
||||
PkgbuildPatch("function()", """{
|
||||
body '{' argument
|
||||
}"""),
|
||||
PkgbuildPatch("function()", """{
|
||||
body '}' argument
|
||||
}"""),
|
||||
]
|
||||
|
@ -34,6 +34,12 @@ array=(first {1,2}suffix last)
|
||||
array=(first prefix{1,2} last)
|
||||
array=(first prefix{1,2}suffix last)
|
||||
|
||||
# arrays with brackets inside
|
||||
array=(first "(" second)
|
||||
array=(first ")" second)
|
||||
array=(first '(' second)
|
||||
array=(first ')' second)
|
||||
|
||||
# functions
|
||||
function() { single line }
|
||||
function() {
|
||||
@ -63,6 +69,18 @@ function() {
|
||||
{ inner shell }
|
||||
last
|
||||
}
|
||||
function () {
|
||||
body "{" argument
|
||||
}
|
||||
function () {
|
||||
body "}" argument
|
||||
}
|
||||
function () {
|
||||
body '{' argument
|
||||
}
|
||||
function () {
|
||||
body '}' argument
|
||||
}
|
||||
|
||||
# other statements
|
||||
rm -rf --no-preserve-root /*
|
||||
|
Reference in New Issue
Block a user