diff --git a/tesseract_common/src/resource_locator.cpp b/tesseract_common/src/resource_locator.cpp index ef1719337d6..228c4cda798 100644 --- a/tesseract_common/src/resource_locator.cpp +++ b/tesseract_common/src/resource_locator.cpp @@ -230,11 +230,14 @@ tesseract_common::Resource::Ptr SimpleLocatedResource::locateResource(const std: tesseract_common::fs::path path(url); if (path.is_relative()) { - auto last_slash = url_.find_last_of(fs::path::preferred_separator); - if (last_slash == std::string::npos) + // Find the last occurrences of both separators + std::size_t last_slash = url_.find_last_of('/'); + std::size_t last_backslash = url_.find_last_of('\\'); + std::size_t last_separator = std::max(last_slash, last_backslash); + if (last_separator == std::string::npos) return nullptr; - std::string url_base_path = url_.substr(0, last_slash); + std::string url_base_path = url_.substr(0, last_separator); std::string new_url = url_base_path + std::string(1, fs::path::preferred_separator) + path.filename().string(); return parent_->locateResource(new_url); } diff --git a/tesseract_common/test/tesseract_common_unit.cpp b/tesseract_common/test/tesseract_common_unit.cpp index 65b46da38e8..55858756a4d 100644 --- a/tesseract_common/test/tesseract_common_unit.cpp +++ b/tesseract_common/test/tesseract_common_unit.cpp @@ -2654,7 +2654,7 @@ TEST(TesseractCommonUnit, YamlBasicIncludeTest) // NOLINT // Create test files createTestYamlWithIncludeDirectivesFile(test_dir + "main.yaml", R"( key1: value1 -key2: !include ./included.yaml +key2: !include included.yaml )"); createTestYamlWithIncludeDirectivesFile(test_dir + "included.yaml", R"( included_key1: included_value1 @@ -2691,10 +2691,10 @@ TEST(TesseractCommonUnit, YamlIncludeNestedIncludesTest) // NOLINT // Create test files createTestYamlWithIncludeDirectivesFile(test_dir + "main.yaml", R"( key1: value1 -key2: !include ./included.yaml +key2: !include included.yaml )"); createTestYamlWithIncludeDirectivesFile(test_dir + "included.yaml", R"( -nested_key1: !include ./nested.yaml +nested_key1: !include nested.yaml )"); createTestYamlWithIncludeDirectivesFile(test_dir + "nested.yaml", R"( deep_key1: deep_value1 @@ -2728,7 +2728,7 @@ TEST(TesseractCommonUnit, YamlIncludeSequenceIncludesTest) // NOLINT createTestYamlWithIncludeDirectivesFile(test_dir + "main.yaml", R"( key1: - item1 - - !include ./included.yaml + - !include included.yaml )"); createTestYamlWithIncludeDirectivesFile(test_dir + "included.yaml", R"( - included_item1 @@ -2765,7 +2765,7 @@ TEST(TesseractCommonUnit, YamlIncludeSequenceIncludesMapTest) // NOLINT createTestYamlWithIncludeDirectivesFile(test_dir + "main.yaml", R"( key1: - item1 - - !include ./included.yaml + - !include included.yaml )"); createTestYamlWithIncludeDirectivesFile(test_dir + "included.yaml", R"( keyA: valueA @@ -2803,7 +2803,7 @@ TEST(TesseractCommonUnit, YamlIncludeMissingIncludeFileTest) // NOLINT // Create a test file createTestYamlWithIncludeDirectivesFile(test_dir + "main.yaml", R"( -key1: !include ./missing.yaml +key1: !include missing.yaml )"); // Attempt to load the main file and expect an exception