Skip to content

Commit e004194

Browse files
fixup
1 parent dd778c0 commit e004194

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

tesseract_common/src/resource_locator.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,14 @@ tesseract_common::Resource::Ptr SimpleLocatedResource::locateResource(const std:
230230
tesseract_common::fs::path path(url);
231231
if (path.is_relative())
232232
{
233-
auto last_slash = url_.find_last_of(fs::path::preferred_separator);
234-
if (last_slash == std::string::npos)
233+
// Find the last occurrences of both separators
234+
std::size_t last_slash = url_.find_last_of('/');
235+
std::size_t last_backslash = url_.find_last_of('\\');
236+
std::size_t last_separator = std::max(last_slash, last_backslash);
237+
if (last_separator == std::string::npos)
235238
return nullptr;
236239

237-
std::string url_base_path = url_.substr(0, last_slash);
240+
std::string url_base_path = url_.substr(0, last_separator);
238241
std::string new_url = url_base_path + std::string(1, fs::path::preferred_separator) + path.filename().string();
239242
return parent_->locateResource(new_url);
240243
}

tesseract_common/test/tesseract_common_unit.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,7 +2654,7 @@ TEST(TesseractCommonUnit, YamlBasicIncludeTest) // NOLINT
26542654
// Create test files
26552655
createTestYamlWithIncludeDirectivesFile(test_dir + "main.yaml", R"(
26562656
key1: value1
2657-
key2: !include ./included.yaml
2657+
key2: !include included.yaml
26582658
)");
26592659
createTestYamlWithIncludeDirectivesFile(test_dir + "included.yaml", R"(
26602660
included_key1: included_value1
@@ -2691,10 +2691,10 @@ TEST(TesseractCommonUnit, YamlIncludeNestedIncludesTest) // NOLINT
26912691
// Create test files
26922692
createTestYamlWithIncludeDirectivesFile(test_dir + "main.yaml", R"(
26932693
key1: value1
2694-
key2: !include ./included.yaml
2694+
key2: !include included.yaml
26952695
)");
26962696
createTestYamlWithIncludeDirectivesFile(test_dir + "included.yaml", R"(
2697-
nested_key1: !include ./nested.yaml
2697+
nested_key1: !include nested.yaml
26982698
)");
26992699
createTestYamlWithIncludeDirectivesFile(test_dir + "nested.yaml", R"(
27002700
deep_key1: deep_value1
@@ -2728,7 +2728,7 @@ TEST(TesseractCommonUnit, YamlIncludeSequenceIncludesTest) // NOLINT
27282728
createTestYamlWithIncludeDirectivesFile(test_dir + "main.yaml", R"(
27292729
key1:
27302730
- item1
2731-
- !include ./included.yaml
2731+
- !include included.yaml
27322732
)");
27332733
createTestYamlWithIncludeDirectivesFile(test_dir + "included.yaml", R"(
27342734
- included_item1
@@ -2765,7 +2765,7 @@ TEST(TesseractCommonUnit, YamlIncludeSequenceIncludesMapTest) // NOLINT
27652765
createTestYamlWithIncludeDirectivesFile(test_dir + "main.yaml", R"(
27662766
key1:
27672767
- item1
2768-
- !include ./included.yaml
2768+
- !include included.yaml
27692769
)");
27702770
createTestYamlWithIncludeDirectivesFile(test_dir + "included.yaml", R"(
27712771
keyA: valueA
@@ -2803,7 +2803,7 @@ TEST(TesseractCommonUnit, YamlIncludeMissingIncludeFileTest) // NOLINT
28032803

28042804
// Create a test file
28052805
createTestYamlWithIncludeDirectivesFile(test_dir + "main.yaml", R"(
2806-
key1: !include ./missing.yaml
2806+
key1: !include missing.yaml
28072807
)");
28082808

28092809
// Attempt to load the main file and expect an exception

0 commit comments

Comments
 (0)