From f99b399be3d5a6b543734f53a4c4760d45ec30c1 Mon Sep 17 00:00:00 2001 From: Favo Yang Date: Mon, 18 May 2020 23:19:42 +0800 Subject: [PATCH] fix: clean group name internally (close: #27) --- Editor/AddressableImportRule.cs | 11 ++++++++++- Tests/Editor/AddressableImportRuleTests.cs | 20 ++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Editor/AddressableImportRule.cs b/Editor/AddressableImportRule.cs index f14310d..4f9e46a 100644 --- a/Editor/AddressableImportRule.cs +++ b/Editor/AddressableImportRule.cs @@ -56,6 +56,15 @@ public class AddressableImportRule [Tooltip("The group name in which the Addressable will be added. Leave blank for the default group.")] public string groupName; + /// + /// Cleaned group name. + /// + string CleanedGroupName { + get { + return groupName.Trim().Replace('/', '-').Replace('\\', '-'); + } + } + /// /// Defines if labels will be added or replaced. /// @@ -134,7 +143,7 @@ public string ParseGroupReplacement(string assetPath) if (string.IsNullOrWhiteSpace(path) || string.IsNullOrWhiteSpace(groupName)) return null; // Parse path elements. - var replacement = AddressableImportRegex.ParsePath(assetPath, groupName); + var replacement = AddressableImportRegex.ParsePath(assetPath, CleanedGroupName); // Parse this.path regex. if (matchType == AddressableImportRuleMatchType.Regex) { string pathRegex = path; diff --git a/Tests/Editor/AddressableImportRuleTests.cs b/Tests/Editor/AddressableImportRuleTests.cs index e5923dc..1662aeb 100644 --- a/Tests/Editor/AddressableImportRuleTests.cs +++ b/Tests/Editor/AddressableImportRuleTests.cs @@ -58,14 +58,30 @@ public void ParseGroupReplacementTest() rule.path = " "; rule.groupName = "somegroup"; Assert.IsNull(rule.ParseGroupReplacement("Assets/Sprites/cat/cat.png")); - // Test empy groupName + // Test empty groupName rule.matchType = AddressableImportRuleMatchType.Wildcard; - rule.path = @"Assets/Sprites/*/*.png"; + rule.path = "Assets/Sprites/*/*.png"; rule.groupName = ""; Assert.IsNull(rule.ParseGroupReplacement("Assets/Sprites/cat/cat.png")); rule.path = "Assets/Sprites/*/*.png"; rule.groupName = " "; Assert.IsNull(rule.ParseGroupReplacement("Assets/Sprites/cat/cat.png")); + // Test empty spaces in groupName + rule.matchType = AddressableImportRuleMatchType.Wildcard; + rule.path = "Assets/Sprites/*/*.png"; + rule.groupName = " group-a"; + Assert.AreEqual("group-a", rule.ParseGroupReplacement("Assets/Sprites/cat/cat.png")); + rule.groupName = "group-a "; + Assert.AreEqual("group-a", rule.ParseGroupReplacement("Assets/Sprites/cat/cat.png")); + rule.groupName = " group-a "; + Assert.AreEqual("group-a", rule.ParseGroupReplacement("Assets/Sprites/cat/cat.png")); + // Test splash in groupName + rule.matchType = AddressableImportRuleMatchType.Wildcard; + rule.path = "Assets/Sprites/*/*.png"; + rule.groupName = "group/a"; + Assert.AreEqual("group-a", rule.ParseGroupReplacement("Assets/Sprites/cat/cat.png")); + rule.groupName = @"group\a "; + Assert.AreEqual("group-a", rule.ParseGroupReplacement("Assets/Sprites/cat/cat.png")); // Test static groupName rule.matchType = AddressableImportRuleMatchType.Wildcard; rule.path = "Assets/Sprites/*/*.png";