@@ -139,6 +139,17 @@ + (void)configureWithOptions:(FIROptions *)options {
139
139
[FIRApp configureWithName: kFIRDefaultAppName options: options];
140
140
}
141
141
142
+ + (NSCharacterSet *)applicationNameAllowedCharacters {
143
+ static NSCharacterSet *applicationNameAllowedCharacters;
144
+ static dispatch_once_t onceToken;
145
+ dispatch_once (&onceToken, ^{
146
+ NSMutableCharacterSet *allowedNameCharacters = [NSMutableCharacterSet alphanumericCharacterSet ];
147
+ [allowedNameCharacters addCharactersInString: @" -_" ];
148
+ applicationNameAllowedCharacters = [allowedNameCharacters copy ];
149
+ });
150
+ return applicationNameAllowedCharacters;
151
+ }
152
+
142
153
+ (void )configureWithName : (NSString *)name options : (FIROptions *)options {
143
154
if (!name || !options) {
144
155
[NSException raise :kFirebaseCoreErrorDomain format: @" Neither name nor options can be nil." ];
@@ -156,14 +167,12 @@ + (void)configureWithName:(NSString *)name options:(FIROptions *)options {
156
167
FIRLogDebug (kFIRLoggerCore , @" I-COR000001" , @" Configuring the default app." );
157
168
} else {
158
169
// Validate the app name and ensure it hasn't been configured already.
159
- for (NSUInteger charIndex = 0 ; charIndex < name.length ; charIndex++) {
160
- char character = [name characterAtIndex: charIndex];
161
- if (!((character >= ' a' && character <= ' z' ) || (character >= ' A' && character <= ' Z' ) ||
162
- (character >= ' 0' && character <= ' 9' ) || character == ' _' || character == ' -' )) {
163
- [NSException raise :kFirebaseCoreErrorDomain
164
- format: @" App name can only contain alphanumeric (A-Z,a-z,0-9), "
165
- @" hyphen (-), and underscore (_) characters" ];
166
- }
170
+ NSCharacterSet *nameCharacters = [NSCharacterSet characterSetWithCharactersInString: name];
171
+
172
+ if (![[self applicationNameAllowedCharacters ] isSupersetOfSet: nameCharacters]) {
173
+ [NSException raise :kFirebaseCoreErrorDomain
174
+ format: @" App name can only contain alphanumeric, "
175
+ @" hyphen (-), and underscore (_) characters" ];
167
176
}
168
177
169
178
@synchronized (self) {
0 commit comments