diff --git a/source/blender/blenkernel/intern/image_save.cc b/source/blender/blenkernel/intern/image_save.cc index 87d113ea1c3..0cbfece36ef 100644 --- a/source/blender/blenkernel/intern/image_save.cc +++ b/source/blender/blenkernel/intern/image_save.cc @@ -179,7 +179,7 @@ bool BKE_image_save_options_init(ImageSaveOptions *opts, } else { BLI_path_join(opts->filepath, sizeof(opts->filepath), "//", ima->id.name + 2); - BLI_path_make_safe(opts->filepath); + BLI_path_make_safe_filename(opts->filepath + 2); BLI_path_abs(opts->filepath, is_prev_save ? G.filepath_last_image : BKE_main_blendfile_path(bmain)); } diff --git a/source/blender/blenlib/BLI_path_utils.hh b/source/blender/blenlib/BLI_path_utils.hh index d59b81f75e3..f8b16299acf 100644 --- a/source/blender/blenlib/BLI_path_utils.hh +++ b/source/blender/blenlib/BLI_path_utils.hh @@ -98,6 +98,11 @@ const char *BLI_path_parent_dir_end(const char *path, size_t path_len) * https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words ) * by underscores ('_'). * + * \note This should only be used when creating new paths from user-input or + * to sanitize a file-names initialized from non-path text such as the name of a data-block. + * It must never be used on references to existing paths since this function + * will change the paths causing them to become invalid. + * * \note Space case ' ' is a bit of an edge case here - in theory it is allowed, * but again can be an issue in some cases, so we simply replace it by an underscore too * (good practice anyway). @@ -118,6 +123,10 @@ bool BLI_path_make_safe_filename(char *filename) ATTR_NONNULL(1); * Make given path OS-safe. * * \return true if \a path was changed, false otherwise. + * + * \note When the file-name component of the path may not use safe characters, + * #BLI_path_make_safe_filename should be used on the file-name part, + * so slashes are replaced, treating the text as a single file-name. */ bool BLI_path_make_safe(char *path) ATTR_NONNULL(1);