Skip to content

Commit

Permalink
fix: escape strings.xml app name
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagoappereira committed Dec 9, 2021
1 parent a1ed1c0 commit 64ed3b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var path = require('path');
var fs = require('fs-extra');
var utils = require('./utils');
var check_reqs = require('./check_reqs');
const { escape } = require('lodash');
var ROOT = path.join(__dirname, '..');
const { createEditor } = require('properties-parser');

Expand Down Expand Up @@ -255,7 +256,7 @@ exports.create = function (project_path, config, options, events) {
fs.ensureDirSync(activity_dir);
fs.copySync(path.join(project_template_dir, 'Activity.java'), activity_path);
utils.replaceFileContents(activity_path, /__ACTIVITY__/, safe_activity_name);
utils.replaceFileContents(path.join(app_path, 'res', 'values', 'strings.xml'), /__NAME__/, project_name);
utils.replaceFileContents(path.join(app_path, 'res', 'values', 'strings.xml'), /__NAME__/, escape(project_name));
utils.replaceFileContents(activity_path, /__ID__/, package_name);

var manifest = new AndroidManifest(path.join(project_template_dir, 'AndroidManifest.xml'));
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ describe('create', function () {
});
});

it('should interpolate the escaped project name into strings.xml', () => {
config_mock.name.and.returnValue('<Incredible&App>');
return create.create(project_path, config_mock, {}, events_mock).then(() => {
expect(utils.replaceFileContents).toHaveBeenCalledWith(path.join(app_path, 'res', 'values', 'strings.xml'), /__NAME__/, '&lt;Incredible&amp;App&gt;');
});
});

it('should copy template scripts into generated project', () => {
return create.create(project_path, config_mock, {}, events_mock).then(() => {
expect(create.copyScripts).toHaveBeenCalledWith(project_path);
Expand Down

0 comments on commit 64ed3b7

Please sign in to comment.