Skip to content

Commit 9f440ac

Browse files
committed
feat: added validation to <branch-config>
1 parent 55ed145 commit 9f440ac

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

hooks/lib/sdk/configXml.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,21 @@
9999
if (preferences.branchKey === null) {
100100
throw new Error('BRANCH SDK: Missing "branch-key" in <branch-config> in your config.xml. https://goo.gl/GijGKP')
101101
}
102-
if (preferences.uriScheme === null) {
103-
throw new Error('BRANCH SDK: Missing "uri-scheme" in <branch-config> in your config.xml. https://goo.gl/GijGKP')
102+
if (preferences.uriScheme === null || !/^[a-zA-Z0-9-.]*$/.test(preferences.uriScheme)) {
103+
throw new Error('BRANCH SDK: Invalid "uri-scheme" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP')
104104
}
105-
if (preferences.linkDomain === null) {
106-
throw new Error('BRANCH SDK: Missing "uri-scheme" in <branch-config> in your config.xml. https://goo.gl/GijGKP')
105+
if (preferences.linkDomain === null || !/^(?!.*?www).*([a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+.*)$/.test(preferences.linkDomain)) {
106+
throw new Error('BRANCH SDK: Invalid "link-domain" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP')
107+
}
108+
if (preferences.iosTeamRelease === null || !/^[a-zA-Z0-9]{10}$/.test(preferences.iosTeamRelease)) {
109+
throw new Error('BRANCH SDK: Invalid "ios-team-release" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP')
110+
}
111+
if (preferences.iosTeamDebug !== null && !/^[a-zA-Z0-9]{10}$/.test(preferences.iosTeamDebug)) {
112+
throw new Error('BRANCH SDK: Invalid "ios-team-debug" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP')
113+
}
114+
if (preferences.androidPrefix !== null && !/^[/].[a-zA-Z0-9]{3}$/.test(preferences.androidPrefix)) {
115+
throw new Error('BRANCH SDK: Invalid "android-prefix" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP')
107116
}
108-
if (preferences.iosTeamProd === null) {
109-
throw new Error('BRANCH SDK: Missing "ios-team-prod" in <branch-config> in your config.xml. https://goo.gl/GijGKP')
110117
if (!(preferences.androidTestMode === 'true' || preferences.androidTestMode === 'false')) {
111118
throw new Error('BRANCH SDK: Invalid "android-testmode" in <branch-config> in your config.xml. Docs https://goo.gl/GijGKP')
112119
}

0 commit comments

Comments
 (0)