Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Armstrong committed Jan 2, 2025
1 parent dd778c0 commit e004194
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
9 changes: 6 additions & 3 deletions tesseract_common/src/resource_locator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions tesseract_common/test/tesseract_common_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e004194

Please sign in to comment.