[pp:metadata] fix handling of empty directory paths (#7296)
This commit is contained in:
@@ -269,7 +269,7 @@ class PathFormat():
|
||||
try:
|
||||
for fmt in self.directory_formatters:
|
||||
segment = fmt(kwdict).strip()
|
||||
if strip and segment != "..":
|
||||
if strip and segment not in {".", ".."}:
|
||||
# remove trailing dots and spaces (#647)
|
||||
segment = segment.rstrip(strip)
|
||||
if segment:
|
||||
|
||||
@@ -180,7 +180,10 @@ class MetadataPP(PostProcessor):
|
||||
pathfmt.directory_formatters = self._directory_formatters
|
||||
pathfmt.directory_conditions = ()
|
||||
segments = pathfmt.build_directory(pathfmt.kwdict)
|
||||
directory = pathfmt.clean_path(os.sep.join(segments) + os.sep)
|
||||
if segments:
|
||||
directory = pathfmt.clean_path(os.sep.join(segments) + os.sep)
|
||||
else:
|
||||
directory = "." + os.sep
|
||||
return os.path.join(self._base(pathfmt), directory)
|
||||
finally:
|
||||
pathfmt.directory_conditions = conditions
|
||||
|
||||
@@ -511,6 +511,17 @@ class MetadataTest(BasePostprocessorTest):
|
||||
path = self.pathfmt.realdirectory + "../json/12500/file.ext.json"
|
||||
m.assert_called_once_with(path, "w", encoding="utf-8")
|
||||
|
||||
def test_metadata_directory_empty(self):
|
||||
self._create(
|
||||
{"directory": []},
|
||||
)
|
||||
|
||||
with patch("builtins.open", mock_open()) as m:
|
||||
self._trigger()
|
||||
|
||||
path = self.pathfmt.realdirectory + "./file.ext.json"
|
||||
m.assert_called_once_with(path, "w", encoding="utf-8")
|
||||
|
||||
def test_metadata_basedirectory(self):
|
||||
self._create({"base-directory": True})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user