Skip to content

Commit 50fcd3b

Browse files
committed
Fix quoted file paths
Signed-off-by: Uilian Ries <uilianr@jfrog.com>
1 parent e07cb8b commit 50fcd3b

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

.github/scripts/validate-cci-patch-ng.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ for it in $RECIPES; do
7373
"ERROR: Missing binary"
7474
"Failed to establish a new connection"
7575
"ConanException: sha256 signature failed"
76+
"ConanException: Error downloading file"
77+
"ConanException: Cannot find"
78+
"certificate verify failed: certificate has expired"
7679
"NotFoundException: Not found"
7780
)
7881
# check if any allowed error is in the output

patch_ng.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,9 @@ def _normalize_filenames(self):
900900
p.source = xnormpath(p.source)
901901
p.target = xnormpath(p.target)
902902

903+
p.source = p.source.strip(b'"')
904+
p.target = p.target.strip(b'"')
905+
903906
sep = b'/' # sep value can be hardcoded, but it looks nice this way
904907

905908
# references to parent are not allowed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
diff '--color=auto' -ruN "b/Wrapper/FreeImage.NET/cs/Samples/Sample 01 - Loading and saving/Program.cs" "a/Wrapper/FreeImage.NET/cs/Samples/Sample 01 - Loading and saving/Program.cs"
2+
--- "b/Wrapper/FreeImage.NET/cs/Samples/Sample 01 - Loading and saving/Program.cs" 2025-10-08 15:56:02.302486070 +0200
3+
+++ "a/Wrapper/FreeImage.NET/cs/Samples/Sample 01 - Loading and saving/Program.cs" 2025-10-08 15:21:46.283174211 +0200
4+
@@ -1 +1 @@
5+
-feriunt summos, fulmina montes.
6+
+lux oculorum laetificat animam.

tests/run_tests.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,40 @@ def test_add_move_and_update_file(self):
589589
content = f.read()
590590
self.assertTrue(b'dum tempus habemus, operemur bonum' in content)
591591

592+
class TestPatchFileWithSpaces(unittest.TestCase):
593+
594+
def setUp(self):
595+
self.save_cwd = os.getcwd()
596+
self.tmpdir = mkdtemp(prefix=self.__class__.__name__)
597+
shutil.copytree(join(TESTS, 'filewithspace'), join(self.tmpdir, 'filewithspace'))
598+
patch_folder = join(self.tmpdir, "a", "Wrapper", "FreeImage.NET", "cs", "Samples", "Sample 01 - Loading and saving")
599+
os.makedirs(patch_folder, exist_ok=True)
600+
self.program_cs = join(patch_folder, "Program.cs")
601+
with open(self.program_cs, 'w') as fd:
602+
fd.write("feriunt summos, fulmina montes.")
603+
604+
def tearDown(self):
605+
os.chdir(self.save_cwd)
606+
remove_tree_force(self.tmpdir)
607+
608+
def test_patch_with_white_space(self):
609+
"""When a patch file is generated using `diff -ruN b/ a/` command, and
610+
contains white spaces in the file path, the patch should be applied correctly.
611+
612+
Reported by https://github.com/conan-io/conan/issues/16727
613+
"""
614+
615+
os.chdir(self.tmpdir)
616+
print("TMPDIR:", self.tmpdir)
617+
pto = patch_ng.fromfile(join(self.tmpdir, 'filewithspace', '0001-quote.diff'))
618+
self.assertEqual(len(pto), 1)
619+
self.assertEqual(pto.items[0].type, patch_ng.PLAIN)
620+
self.assertTrue(pto.apply())
621+
with open(self.program_cs, 'rb') as f:
622+
content = f.read()
623+
self.assertTrue(b'lux oculorum laetificat animam.' in content)
624+
625+
592626
class TestHelpers(unittest.TestCase):
593627
# unittest setting
594628
longMessage = True

0 commit comments

Comments
 (0)