Skip to content

Commit

Permalink
Allow relative path in _parse_include
Browse files Browse the repository at this point in the history
  • Loading branch information
DWonMtl authored and ereOn committed Oct 11, 2016
1 parent b577e3d commit 5ef623e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
10 changes: 6 additions & 4 deletions redis_lua/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,16 +402,18 @@ def _parse_include(
get_script_by_name,
):
match = re.match(
r'^\s*%include\s+"(?P<name>[\w\d_\-/\\]+)"\s*$',
r'^\s*%include\s+"(?P<name>[\w\d_\-/\\.]+)"\s*$',
statement,
)

if match:
# We don't want backslashes in script names. Life is already
# complex enough.
name = os.path.join(
current_path,
match.group('name'),
name = os.path.relpath(
os.path.join(
current_path,
match.group('name'),
)
).replace(os.path.sep, '/')
script = get_script_by_name(name=name)

Expand Down
18 changes: 15 additions & 3 deletions tests/test_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,8 @@ def test_extract_regions_include(self):
'%include "foo"',
'%include "foo"',
'local e = 4;',
'%include "../foo"',
'%include "./bar/../foo"',
]
content = '\n'.join(contents)
script = Script(
Expand Down Expand Up @@ -779,14 +781,24 @@ def test_extract_regions_include(self):
content='%include "foo"',
),
TextRegion(content=contents[5]),
ScriptRegion(
script=script,
content='%include "../foo"',
),
ScriptRegion(
script=script,
content='%include "./bar/../foo"',
),
],
regions,
)
self.assertEqual(
[
call(name="./%s" % script.name),
call(name="./%s" % script.name),
call(name="./%s" % script.name),
call(name="%s" % script.name),
call(name="%s" % script.name),
call(name="%s" % script.name),
call(name="../%s" % script.name),
call(name="%s" % script.name),
],
get_script_by_name.mock_calls[:],
)
Expand Down

0 comments on commit 5ef623e

Please sign in to comment.