Skip to content

Commit

Permalink
fix: clean group name internally (close: #27)
Browse files Browse the repository at this point in the history
  • Loading branch information
favoyang committed May 18, 2020
1 parent c366986 commit f99b399
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
11 changes: 10 additions & 1 deletion Editor/AddressableImportRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// Cleaned group name.
/// </summary>
string CleanedGroupName {
get {
return groupName.Trim().Replace('/', '-').Replace('\\', '-');
}
}

/// <summary>
/// Defines if labels will be added or replaced.
/// </summary>
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 18 additions & 2 deletions Tests/Editor/AddressableImportRuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit f99b399

Please sign in to comment.