Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[firebase-analytics] Fix numeric chars not allow in event names (#8516)
The eventName and userPropertyName for a firebase event support alphanumeric values but the regex was not allowing numeric characters. Updates regex and adds additional check to ensure the first char is alphabetic.
- Loading branch information
1 parent
ae90e59
commit a5bec1f
Showing
7 changed files
with
114 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/expo-firebase-analytics/build/FirebaseAnalyticsJS.d.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
31 changes: 13 additions & 18 deletions
31
packages/expo-firebase-analytics/build/FirebaseAnalyticsJS.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
packages/expo-firebase-analytics/build/FirebaseAnalyticsJS.js.map
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
packages/expo-firebase-analytics/src/__tests__/FirebaseAnalyticsJS-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import FirebaseAnalyticsJS from '../FirebaseAnalyticsJS'; | ||
|
||
let eventName = ''; | ||
const expectedErrorMessage = (name, eventName, maxLength) => | ||
`Invalid ${name} (${eventName}) specified. Should contain 1 to ${maxLength} alphanumeric characters or underscores. The name must start with an alphabetic character.`; | ||
const options = { | ||
clientId: '0', | ||
sessionId: '0', | ||
}; | ||
|
||
it(`Verfies parseEvent eventName validation`, async () => { | ||
const name = 'event-name'; | ||
expect.assertions(3); | ||
FirebaseAnalyticsJS.parseEvent(options, 'MyAnalyticsEvent'); | ||
|
||
try { | ||
eventName = '_MyAnalyticsEvent'; | ||
FirebaseAnalyticsJS.parseEvent(options, eventName); | ||
} catch (error) { | ||
expect(error.message).toBe(expectedErrorMessage(name, eventName, 40)); | ||
} | ||
|
||
try { | ||
eventName = '0MyAnalyticsEvent'; | ||
FirebaseAnalyticsJS.parseEvent(options, eventName); | ||
} catch (error) { | ||
expect(error.message).toBe(expectedErrorMessage(name, eventName, 40)); | ||
} | ||
|
||
FirebaseAnalyticsJS.parseEvent(options, 'MyAnalyticsEvent0'); | ||
|
||
try { | ||
eventName = '0SuperLongNameThatIsMoreThan40CharactersInLength'; | ||
FirebaseAnalyticsJS.parseEvent(options, eventName); | ||
} catch (error) { | ||
expect(error.message).toBe(expectedErrorMessage(name, eventName, 40)); | ||
} | ||
|
||
FirebaseAnalyticsJS.parseEvent(options, 'user_id'); | ||
}); | ||
|
||
it(`Verfies parseUserProperty userPropertyName validation`, async () => { | ||
const name = 'user-property name'; | ||
expect.assertions(4); | ||
const value = 'value'; | ||
|
||
FirebaseAnalyticsJS.parseUserProperty(options, 'MyAnalyticsEvent', value); | ||
|
||
try { | ||
eventName = '_MyAnalyticsEvent'; | ||
FirebaseAnalyticsJS.parseUserProperty(options, eventName, value); | ||
} catch (error) { | ||
expect(error.message).toBe(expectedErrorMessage(name, eventName, 24)); | ||
} | ||
|
||
try { | ||
eventName = '0MyAnalyticsEvent'; | ||
FirebaseAnalyticsJS.parseUserProperty(options, eventName, value); | ||
} catch (error) { | ||
expect(error.message).toBe(expectedErrorMessage(name, eventName, 24)); | ||
} | ||
|
||
FirebaseAnalyticsJS.parseUserProperty(options, 'MyAnalyticsEvent0', value); | ||
|
||
try { | ||
eventName = '0LongNameThatIsMoreThan24ButLessThan40'; | ||
FirebaseAnalyticsJS.parseUserProperty(options, eventName, value); | ||
} catch (error) { | ||
expect(error.message).toBe(expectedErrorMessage(name, eventName, 24)); | ||
} | ||
|
||
try { | ||
eventName = 'user_id'; | ||
FirebaseAnalyticsJS.parseUserProperty(options, eventName, value); | ||
} catch (error) { | ||
expect(error.message).toBe(expectedErrorMessage(name, eventName, 24)); | ||
} | ||
}); |