From 24b0dab30e7c3ad34decf3495c945c725182ddb8 Mon Sep 17 00:00:00 2001 From: srikappa-amzn Date: Wed, 20 Oct 2021 12:02:46 -0700 Subject: [PATCH 1/3] Make safe asset folder comparison for prefab creation to be case insensitive Signed-off-by: srikappa-amzn --- .../UI/Prefab/PrefabIntegrationManager.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp index 526912cf29..0bb596d0f6 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp @@ -800,16 +800,14 @@ namespace AzToolsFramework } else { - QString cleanSaveAs(QDir::cleanPath(prefabPath)); + AZ::IO::FixedMaxPath lexicallyNormalPath = AZ::IO::PathView(prefabPath.toUtf8().constData()).LexicallyNormal(); bool isPathSafeForAssets = false; - for (AZStd::string assetSafeFolder : assetSafeFolders) + for (AZ::IO::Path assetSafeFolder : assetSafeFolders) { - QString cleanAssetSafeFolder(QDir::cleanPath(assetSafeFolder.c_str())); - // Compare using clean paths so slash direction does not matter. - // Note that this comparison is case sensitive because some file systems - // Open 3D Engine supports are case sensitive. - if (cleanSaveAs.startsWith(cleanAssetSafeFolder)) + // Check if the prefabPath is relative to the safe asset directory. + // The Path classes are being used to make this check case insensitive. + if (lexicallyNormalPath.IsRelativeTo(assetSafeFolder)) { isPathSafeForAssets = true; break; From 4ed73a0b9136b130bc707937207b3e497d01e825 Mon Sep 17 00:00:00 2001 From: srikappa-amzn Date: Thu, 21 Oct 2021 09:11:11 -0700 Subject: [PATCH 2/3] Use case insensitive folder path comparison for creating slices Signed-off-by: srikappa-amzn --- .../AzToolsFramework/Slice/SliceUtilities.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Slice/SliceUtilities.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Slice/SliceUtilities.cpp index aca667b9aa..69d4a95b59 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Slice/SliceUtilities.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Slice/SliceUtilities.cpp @@ -2648,16 +2648,14 @@ namespace AzToolsFramework } else { - QString cleanSaveAs(QDir::cleanPath(slicePath)); + AZ::IO::FixedMaxPath lexicallyNormalPath = AZ::IO::PathView(slicePath.toUtf8().constData()).LexicallyNormal(); bool isPathSafeForAssets = false; - for (AZStd::string assetSafeFolder : assetSafeFolders) + for (AZ::IO::Path assetSafeFolder : assetSafeFolders) { - QString cleanAssetSafeFolder(QDir::cleanPath(assetSafeFolder.c_str())); - // Compare using clean paths so slash direction does not matter. - // Note that this comparison is case sensitive because some file systems - // Open 3D Engine supports are case sensitive. - if (cleanSaveAs.startsWith(cleanAssetSafeFolder)) + // Check if the slice path is relative to the safe asset directory. + // The Path classes are being used to make this check case insensitive. + if (lexicallyNormalPath.IsRelativeTo(assetSafeFolder)) { isPathSafeForAssets = true; break; From 33490ed6dfe03431057567698703cfc8fab4946b Mon Sep 17 00:00:00 2001 From: srikappa-amzn Date: Thu, 21 Oct 2021 11:42:41 -0700 Subject: [PATCH 3/3] Avoided a string copy by using path view Signed-off-by: srikappa-amzn --- .../AzToolsFramework/Slice/SliceUtilities.cpp | 5 +++-- .../AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Slice/SliceUtilities.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Slice/SliceUtilities.cpp index 69d4a95b59..c13f7dd848 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Slice/SliceUtilities.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Slice/SliceUtilities.cpp @@ -2651,11 +2651,12 @@ namespace AzToolsFramework AZ::IO::FixedMaxPath lexicallyNormalPath = AZ::IO::PathView(slicePath.toUtf8().constData()).LexicallyNormal(); bool isPathSafeForAssets = false; - for (AZ::IO::Path assetSafeFolder : assetSafeFolders) + for (const AZStd::string& assetSafeFolder : assetSafeFolders) { + AZ::IO::PathView assetSafeFolderView(assetSafeFolder); // Check if the slice path is relative to the safe asset directory. // The Path classes are being used to make this check case insensitive. - if (lexicallyNormalPath.IsRelativeTo(assetSafeFolder)) + if (lexicallyNormalPath.IsRelativeTo(assetSafeFolderView)) { isPathSafeForAssets = true; break; diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp index 0bb596d0f6..7a50961910 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/UI/Prefab/PrefabIntegrationManager.cpp @@ -803,11 +803,12 @@ namespace AzToolsFramework AZ::IO::FixedMaxPath lexicallyNormalPath = AZ::IO::PathView(prefabPath.toUtf8().constData()).LexicallyNormal(); bool isPathSafeForAssets = false; - for (AZ::IO::Path assetSafeFolder : assetSafeFolders) + for (const AZStd::string& assetSafeFolder : assetSafeFolders) { + AZ::IO::PathView assetSafeFolderView(assetSafeFolder); // Check if the prefabPath is relative to the safe asset directory. // The Path classes are being used to make this check case insensitive. - if (lexicallyNormalPath.IsRelativeTo(assetSafeFolder)) + if (lexicallyNormalPath.IsRelativeTo(assetSafeFolderView)) { isPathSafeForAssets = true; break;