diff --git a/source/blender/asset_system/tests/asset_representation_test.cc b/source/blender/asset_system/tests/asset_representation_test.cc index d2ed2c2a5f1..7d62e932ee9 100644 --- a/source/blender/asset_system/tests/asset_representation_test.cc +++ b/source/blender/asset_system/tests/asset_representation_test.cc @@ -132,6 +132,35 @@ TEST_F(AssetRepresentationTest, weak_reference__compare) other.relative_asset_identifier = "path/to/an/asset"; EXPECT_EQ(weak_ref, other); + other.relative_asset_identifier = ""; + EXPECT_NE(weak_ref, other); + other.relative_asset_identifier = nullptr; + EXPECT_NE(weak_ref, other); + + /* Make the destructor work. */ + other.asset_library_identifier = nullptr; + other.relative_asset_identifier = nullptr; + } + + /* Same but comparing windows and unix style paths. */ + { + AssetLibraryService *service = AssetLibraryService::get(); + AssetLibrary *const library = service->get_asset_library_on_disk_custom("My custom lib", + asset_library_root_); + AssetRepresentation &asset = add_dummy_asset(*library, "path/to/an/asset"); + + AssetWeakReference weak_ref = asset.make_weak_reference(); + AssetWeakReference other; + other.asset_library_type = ASSET_LIBRARY_CUSTOM; + other.asset_library_identifier = "My custom lib"; + other.relative_asset_identifier = "path\\to\\an\\asset"; + EXPECT_EQ(weak_ref, other); + + other.relative_asset_identifier = ""; + EXPECT_NE(weak_ref, other); + other.relative_asset_identifier = nullptr; + EXPECT_NE(weak_ref, other); + /* Make the destructor work. */ other.asset_library_identifier = nullptr; other.relative_asset_identifier = nullptr; diff --git a/source/blender/blenkernel/intern/asset_weak_reference.cc b/source/blender/blenkernel/intern/asset_weak_reference.cc index 89447e719e7..bcce242973d 100644 --- a/source/blender/blenkernel/intern/asset_weak_reference.cc +++ b/source/blender/blenkernel/intern/asset_weak_reference.cc @@ -8,6 +8,7 @@ #include +#include "BLI_path_util.h" #include "BLI_string.h" #include "AS_asset_identifier.hh" @@ -78,10 +79,15 @@ bool operator==(const AssetWeakReference &a, const AssetWeakReference &b) if (a.asset_library_type != b.asset_library_type) { return false; } - if (StringRef(a.asset_library_identifier) != StringRef(b.asset_library_identifier)) { + + const char *a_lib_idenfifier = a.asset_library_identifier ? a.asset_library_identifier : ""; + const char *b_lib_idenfifier = b.asset_library_identifier ? b.asset_library_identifier : ""; + if (BLI_path_cmp_normalized(a_lib_idenfifier, b_lib_idenfifier) != 0) { return false; } - if (StringRef(a.relative_asset_identifier) != StringRef(b.relative_asset_identifier)) { + const char *a_asset_idenfifier = a.relative_asset_identifier ? a.relative_asset_identifier : ""; + const char *b_asset_idenfifier = b.relative_asset_identifier ? b.relative_asset_identifier : ""; + if (BLI_path_cmp_normalized(a_asset_idenfifier, b_asset_idenfifier) != 0) { return false; } return true;