Skip to content

Commit

Permalink
fix(cli): Escape appName from invalid characters on add (#5325)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile committed Dec 17, 2021
1 parent cd8221e commit 033f4ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 6 additions & 5 deletions cli/src/android/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ export async function editProjectSettingsAndroid(
config: Config,
): Promise<void> {
const appId = config.app.appId;
const appName = config.app.appName;
const appName = config.app.appName
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/"/g, '\\"')
.replace(/'/g, "\\'");

const manifestPath = resolve(
config.android.srcMainDirAbs,
Expand Down Expand Up @@ -140,10 +144,7 @@ export async function editProjectSettingsAndroid(
const stringsPath = resolve(config.android.resDirAbs, 'values/strings.xml');
let stringsContent = await readFile(stringsPath, { encoding: 'utf-8' });
stringsContent = stringsContent.replace(/com.getcapacitor.myapp/g, appId);
stringsContent = stringsContent.replace(
/My App/g,
appName.replace(/'/g, `\\'`),
);
stringsContent = stringsContent.replace(/My App/g, appName);

await writeFile(stringsPath, stringsContent);
}
5 changes: 4 additions & 1 deletion cli/src/ios/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ export async function resolvePlugin(plugin: Plugin): Promise<Plugin | null> {
*/
export async function editProjectSettingsIOS(config: Config): Promise<void> {
const appId = config.app.appId;
const appName = config.app.appName;
const appName = config.app.appName
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');

const pbxPath = `${config.ios.nativeXcodeProjDirAbs}/project.pbxproj`;
const plistPath = resolve(config.ios.nativeTargetDirAbs, 'Info.plist');
Expand Down

0 comments on commit 033f4ee

Please sign in to comment.