Skip to content

Commit d07b1eb

Browse files
committed
Fix Ext ID
1 parent 59f49f1 commit d07b1eb

File tree

1 file changed

+18
-6
lines changed
  • src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common

1 file changed

+18
-6
lines changed

src/ServiceManagement/Compute/Commands.ServiceManagement/Extensions/Common/ExtensionRole.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using System;
1616
using System.Text;
17+
using System.Text.RegularExpressions;
1718

1819
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Extensions
1920
{
@@ -28,6 +29,21 @@ public class ExtensionRole
2829
public ExtensionRoleType RoleType { get; private set; }
2930
public bool Default { get; private set; }
3031

32+
private static string RemoveDisallowedCharacters(string roleName)
33+
{
34+
// Remove characters that are not allowed in the extension id
35+
var disallowedCharactersRegex = new Regex(@"[^A-Za-z0-9\-]");
36+
var match = disallowedCharactersRegex.Match(roleName);
37+
38+
while (match.Success)
39+
{
40+
roleName = roleName.Remove(match.Index, match.Length);
41+
match = disallowedCharactersRegex.Match(roleName);
42+
}
43+
44+
return roleName;
45+
}
46+
3147
public ExtensionRole()
3248
{
3349
RoleName = string.Empty;
@@ -48,9 +64,7 @@ public ExtensionRole(string roleName)
4864
else
4965
{
5066
PrefixName = RoleName = roleName.Trim();
51-
PrefixName = PrefixName.Replace(".", string.Empty);
52-
PrefixName = PrefixName.Replace(" ", string.Empty);
53-
PrefixName = PrefixName.Replace("_", string.Empty);
67+
PrefixName = RemoveDisallowedCharacters(PrefixName);
5468
RoleType = ExtensionRoleType.NamedRoles;
5569
Default = false;
5670
}
@@ -63,9 +77,7 @@ public override string ToString()
6377

6478
public string GetExtensionId(string extensionName, string slot, int index)
6579
{
66-
var normalizedExtName = extensionName.Replace(".", string.Empty);
67-
normalizedExtName = normalizedExtName.Replace(" ", string.Empty);
68-
normalizedExtName = normalizedExtName.Replace("_", string.Empty);
80+
var normalizedExtName = RemoveDisallowedCharacters(extensionName);
6981

7082
var suffix = new StringBuilder();
7183
suffix.AppendFormat(ExtensionIdSuffixTemplate, normalizedExtName, slot, index);

0 commit comments

Comments
 (0)