14
14
15
15
using System ;
16
16
using System . Text ;
17
+ using System . Text . RegularExpressions ;
17
18
18
19
namespace Microsoft . WindowsAzure . Commands . ServiceManagement . Extensions
19
20
{
@@ -28,6 +29,21 @@ public class ExtensionRole
28
29
public ExtensionRoleType RoleType { get ; private set ; }
29
30
public bool Default { get ; private set ; }
30
31
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
+
31
47
public ExtensionRole ( )
32
48
{
33
49
RoleName = string . Empty ;
@@ -48,9 +64,7 @@ public ExtensionRole(string roleName)
48
64
else
49
65
{
50
66
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 ) ;
54
68
RoleType = ExtensionRoleType . NamedRoles ;
55
69
Default = false ;
56
70
}
@@ -63,9 +77,7 @@ public override string ToString()
63
77
64
78
public string GetExtensionId ( string extensionName , string slot , int index )
65
79
{
66
- var normalizedExtName = extensionName . Replace ( "." , string . Empty ) ;
67
- normalizedExtName = normalizedExtName . Replace ( " " , string . Empty ) ;
68
- normalizedExtName = normalizedExtName . Replace ( "_" , string . Empty ) ;
80
+ var normalizedExtName = RemoveDisallowedCharacters ( extensionName ) ;
69
81
70
82
var suffix = new StringBuilder ( ) ;
71
83
suffix . AppendFormat ( ExtensionIdSuffixTemplate , normalizedExtName , slot , index ) ;
0 commit comments