Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #1336 #1344

Merged
merged 1 commit into from
Jan 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions utils/android-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ type AndroidPackageValidationError = {

const DISALLOWED_ANDROID_PACKAGE_CHARS_REGEX = /[^a-zA-Z0-9_]/g;
export function generatePackageId(host: string): string {

const parts = host
.split(".")
.reverse()
.map(p => p.trim().toLowerCase())
.map(p => withoutLeadingDigits(p)) // Android Package name parts can't begin with numbers: https://github.com/pwa-builder/PWABuilder/issues/1336#issuecomment-755029058
.filter(p => p.length > 0)
.map(p => p.replace(DISALLOWED_ANDROID_PACKAGE_CHARS_REGEX, "_"))
parts.push("twa");

return parts.join(".");
}

Expand Down Expand Up @@ -171,4 +174,14 @@ export function validateUrl(url: string, base?: string): string | null {
} catch (urlError) {
return urlError;
}
}

function withoutLeadingDigits(input: string): string {
// Check if it starts with a digit.
// If so, prepend "app" to it.
if (input.length && input[0].match(/^\d/)) {
return `app_${input}`
}

return input;
}