From e2ad720568f730fe5ca2f1d0c9c911b339fb58b8 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 7 Jul 2022 03:11:30 +0200 Subject: Fix dir_item::reduce() - use while-loop to remove initial './' - always use spos and reset to pre-len when re-assembling pre+post - break resolve loop once on found idx == npos - limit loop to spos <= haystack.size()-pattern_size - resolve '/./': - remove dead-case '_dot == pre' as resolved upfront - resolve '/../': - test non-starting '/..' at end of pre -> no change. E.g. '../../../bbb' - case 'pre_str = direname(pre)': test '.' (first dir removed) --- test/test_fileutils01.cpp | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'test/test_fileutils01.cpp') diff --git a/test/test_fileutils01.cpp b/test/test_fileutils01.cpp index d10be65..54a59e8 100644 --- a/test/test_fileutils01.cpp +++ b/test/test_fileutils01.cpp @@ -396,7 +396,42 @@ class TestFileUtil01 : TestFileUtilBase { INFO_STR("\n\ntest04_dir_item: 60 '"+path1_+" -> "+di.to_string()+" -> '"+di.path()+"'\n"); REQUIRE( "../../test_data" == di.dirname() ); REQUIRE( "file_01_slink09R1.txt" == di.basename() ); - REQUIRE( "../../test_data/file_01_slink09R1.txt" == di.path() ); + REQUIRE( path1_ == di.path() ); + } + + { + const std::string path1_ = "../../../jaulib/test_data"; + const jau::fs::dir_item di(path1_); + INFO_STR("\n\ntest04_dir_item: 61 '"+path1_+" -> "+di.to_string()+" -> '"+di.path()+"'\n"); + REQUIRE( "../../../jaulib" == di.dirname() ); + REQUIRE( "test_data" == di.basename() ); + REQUIRE( path1_ == di.path() ); + } + + { + const std::string path1_ = "../../../../jaulib/test_data"; + const jau::fs::dir_item di(path1_); + INFO_STR("\n\ntest04_dir_item: 62 '"+path1_+" -> "+di.to_string()+" -> '"+di.path()+"'\n"); + REQUIRE( "../../../../jaulib" == di.dirname() ); + REQUIRE( "test_data" == di.basename() ); + REQUIRE( path1_ == di.path() ); + } + + { + const std::string path1_ = "././././jaulib/test_data"; + const jau::fs::dir_item di(path1_); + INFO_STR("\n\ntest04_dir_item: 63 '"+path1_+" -> "+di.to_string()+" -> '"+di.path()+"'\n"); + REQUIRE( "jaulib" == di.dirname() ); + REQUIRE( "test_data" == di.basename() ); + REQUIRE( "jaulib/test_data" == di.path() ); + } + { + const std::string path1_ = "a/././././jaulib/test_data"; + const jau::fs::dir_item di(path1_); + INFO_STR("\n\ntest04_dir_item: 64 '"+path1_+" -> "+di.to_string()+" -> '"+di.path()+"'\n"); + REQUIRE( "a/jaulib" == di.dirname() ); + REQUIRE( "test_data" == di.basename() ); + REQUIRE( "a/jaulib/test_data" == di.path() ); } { -- cgit v1.2.3