cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaz...@apache.org
Subject ios commit: CB-12402 CB-12206 Properly encode app name to generate XML files
Date Tue, 14 Feb 2017 21:40:33 GMT
Repository: cordova-ios
Updated Branches:
  refs/heads/master 4527e8ef1 -> 7e5c19b8e


CB-12402 CB-12206 Properly encode app name to generate XML files

The build fails due to corrupted xml files at platforms/ios/<APPNAME>.xcworkspace/**

 This closes #288


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/7e5c19b8
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/7e5c19b8
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/7e5c19b8

Branch: refs/heads/master
Commit: 7e5c19b8eee7fd15d706aa64f96a2f7915599c5b
Parents: 4527e8e
Author: Nikita Matrosov <v-nimatr@microsoft.com>
Authored: Mon Feb 13 16:01:02 2017 +0300
Committer: Shazron Abdullah <shazron@gmail.com>
Committed: Tue Feb 14 13:40:09 2017 -0800

----------------------------------------------------------------------
 bin/lib/create.js                    |  9 ++-
 node_modules/xml-escape/LICENSE      | 20 +++++++
 node_modules/xml-escape/README.md    | 38 +++++++++++++
 node_modules/xml-escape/index.js     | 22 ++++++++
 node_modules/xml-escape/package.json | 91 +++++++++++++++++++++++++++++++
 node_modules/xml-escape/test.js      | 29 ++++++++++
 package.json                         |  6 +-
 tests/spec/create.spec.js            |  7 +++
 8 files changed, 218 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/7e5c19b8/bin/lib/create.js
----------------------------------------------------------------------
diff --git a/bin/lib/create.js b/bin/lib/create.js
index 89b9c8a..d62a44c 100755
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -24,6 +24,7 @@ var shell = require('shelljs'),
     path = require('path'),
     fs = require('fs'),
     plist = require('plist'),
+    xmlescape = require('xml-escape'),
     ROOT = path.join(__dirname, '..', '..'),
     events = require('cordova-common').events;
 
@@ -145,10 +146,14 @@ function copyTemplateFiles(project_path, project_name, project_template_dir,
pac
      * - ./__PROJECT_NAME__/Resources/__PROJECT_NAME__-info.plist
      * - ./__PROJECT_NAME__/Resources/__PROJECT_NAME__-Prefix.plist
      */
+
+    // https://issues.apache.org/jira/browse/CB-12402 - Encode XML characters properly
+    var project_name_xml_esc = xmlescape(project_name);
+    shell.sed('-i', /__PROJECT_NAME__/g, project_name_xml_esc, path.join(r+'.xcworkspace',
'contents.xcworkspacedata'));
+    shell.sed('-i', /__PROJECT_NAME__/g, project_name_xml_esc, path.join(r+'.xcworkspace',
'xcshareddata', 'xcschemes', project_name +'.xcscheme'));
+
     var project_name_esc = project_name.replace(/&/g, '\\&');
     shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r+'.xcodeproj', 'project.pbxproj'));
-    shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r+'.xcworkspace', 'contents.xcworkspacedata'));
-    shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r+'.xcworkspace', 'xcshareddata',
'xcschemes', project_name +'.xcscheme'));
     shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, 'Classes', 'AppDelegate.h'));
     shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, 'Classes', 'AppDelegate.m'));
     shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, 'Classes', 'MainViewController.h'));

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/7e5c19b8/node_modules/xml-escape/LICENSE
----------------------------------------------------------------------
diff --git a/node_modules/xml-escape/LICENSE b/node_modules/xml-escape/LICENSE
new file mode 100644
index 0000000..bd261ef
--- /dev/null
+++ b/node_modules/xml-escape/LICENSE
@@ -0,0 +1,20 @@
+The MIT License (MIT)
+
+Copyright (c) 2014 Michael Hernandez
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/7e5c19b8/node_modules/xml-escape/README.md
----------------------------------------------------------------------
diff --git a/node_modules/xml-escape/README.md b/node_modules/xml-escape/README.md
new file mode 100644
index 0000000..5faf9f9
--- /dev/null
+++ b/node_modules/xml-escape/README.md
@@ -0,0 +1,38 @@
+xml-escape
+==========
+
+Escape XML in javascript (NodeJS)
+
+npm install xml-escape
+
+```javascript
+// Warning escape is a reserved word, so maybe best to use xmlescape for var name
+var xmlescape = require('xml-escape');
+
+xmlescape('"hello" \'world\' & false < true > -1');
+
+// output
+// '&quot;hello&quot; &apos;world&apos; &amp; false &lt; true &gt;
-1'
+
+// don't escape some characters
+xmlescape('"hello" \'world\' & false < true > -1', '>"&')
+
+// output
+// '"hello" &apos;world&apos; & false &lt; true > -1'
+```
+
+
+There is also now an ignore function thanks to @jayflo
+
+```javascript
+esc = require('./');
+
+ignore = '"<&'
+// note you should never ignore an &
+output = esc('I am "<&not>" escaped', ignore)
+console.log(output)
+
+//I am "<&not&gt;" escaped
+```
+
+[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/miketheprogrammer/xml-escape/trend.png)](https://bitdeli.com/free
"Bitdeli Badge")

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/7e5c19b8/node_modules/xml-escape/index.js
----------------------------------------------------------------------
diff --git a/node_modules/xml-escape/index.js b/node_modules/xml-escape/index.js
new file mode 100644
index 0000000..8c37325
--- /dev/null
+++ b/node_modules/xml-escape/index.js
@@ -0,0 +1,22 @@
+
+
+var escape = module.exports = function escape(string, ignore) {
+  var pattern;
+
+  if (string === null || string === undefined) return;
+
+  ignore = (ignore || '').replace(/[^&"<>\']/g, '');
+  pattern = '([&"<>\'])'.replace(new RegExp('[' + ignore + ']', 'g'), '');
+
+  return string.replace(new RegExp(pattern, 'g'), function(str, item) {
+            return escape.map[item];
+          })
+}
+
+var map = escape.map = {
+    '>': '&gt;'
+  , '<': '&lt;'
+  , "'": '&apos;'
+  , '"': '&quot;'
+  , '&': '&amp;'
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/7e5c19b8/node_modules/xml-escape/package.json
----------------------------------------------------------------------
diff --git a/node_modules/xml-escape/package.json b/node_modules/xml-escape/package.json
new file mode 100644
index 0000000..51a5714
--- /dev/null
+++ b/node_modules/xml-escape/package.json
@@ -0,0 +1,91 @@
+{
+  "_args": [
+    [
+      {
+        "raw": "xml-escape@^1.1.0",
+        "scope": null,
+        "escapedName": "xml-escape",
+        "name": "xml-escape",
+        "rawSpec": "^1.1.0",
+        "spec": ">=1.1.0 <2.0.0",
+        "type": "range"
+      }
+    ]
+  ],
+  "_from": "xml-escape@>=1.1.0 <2.0.0",
+  "_id": "xml-escape@1.1.0",
+  "_inCache": true,
+  "_location": "/xml-escape",
+  "_nodeVersion": "5.5.0",
+  "_npmOperationalInternal": {
+    "host": "packages-13-west.internal.npmjs.com",
+    "tmp": "tmp/xml-escape-1.1.0.tgz_1457961063163_0.10634087934158742"
+  },
+  "_npmUser": {
+    "name": "mhernandez",
+    "email": "michael.hernandez1988@gmail.com"
+  },
+  "_npmVersion": "3.3.12",
+  "_phantomChildren": {},
+  "_requested": {
+    "raw": "xml-escape@^1.1.0",
+    "scope": null,
+    "escapedName": "xml-escape",
+    "name": "xml-escape",
+    "rawSpec": "^1.1.0",
+    "spec": ">=1.1.0 <2.0.0",
+    "type": "range"
+  },
+  "_requiredBy": [
+    "#USER",
+    "/"
+  ],
+  "_resolved": "https://registry.npmjs.org/xml-escape/-/xml-escape-1.1.0.tgz",
+  "_shasum": "3904c143fa8eb3a0030ec646d2902a2f1b706c44",
+  "_shrinkwrap": null,
+  "_spec": "xml-escape@^1.1.0",
+  "author": {
+    "name": "Michael Hernandez - michael.hernandez1988@gmail.com"
+  },
+  "bugs": {
+    "url": "https://github.com/miketheprogrammer/xml-escape/issues"
+  },
+  "dependencies": {},
+  "description": "Escape XML ",
+  "devDependencies": {
+    "tape": "~2.4.2"
+  },
+  "directories": {},
+  "dist": {
+    "shasum": "3904c143fa8eb3a0030ec646d2902a2f1b706c44",
+    "tarball": "https://registry.npmjs.org/xml-escape/-/xml-escape-1.1.0.tgz"
+  },
+  "gitHead": "c42a09afa81e645ca6881dbaf384d7f3c63735e4",
+  "homepage": "https://github.com/miketheprogrammer/xml-escape",
+  "keywords": [
+    "Escape",
+    "XML",
+    "Unesacpe",
+    "encoding",
+    "xml-escape"
+  ],
+  "license": "MIT License",
+  "main": "index.js",
+  "maintainers": [
+    {
+      "name": "mhernandez",
+      "email": "michael.hernandez1988@gmail.com"
+    }
+  ],
+  "name": "xml-escape",
+  "optionalDependencies": {},
+  "readme": "ERROR: No README data found!",
+  "repository": {
+    "type": "git",
+    "url": "git://github.com/miketheprogrammer/xml-escape.git"
+  },
+  "scripts": {
+    "test": "node test.js"
+  },
+  "version": "1.1.0"
+}

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/7e5c19b8/node_modules/xml-escape/test.js
----------------------------------------------------------------------
diff --git a/node_modules/xml-escape/test.js b/node_modules/xml-escape/test.js
new file mode 100644
index 0000000..21ad218
--- /dev/null
+++ b/node_modules/xml-escape/test.js
@@ -0,0 +1,29 @@
+var test = require('tape');
+var escape = require('./index');
+test("Characters should be escaped properly", function (t) {
+    t.plan(1);
+
+    t.equals(escape('" \' < > &'), '&quot; &apos; &lt; &gt; &amp;');
+})
+
+test("Module should respect ignore string", function (t) {
+    t.plan(3);
+
+    t.equals(escape('" \' < > &', '"'), '" &apos; &lt; &gt; &amp;');
+    t.equals(escape('" \' < > &', '>&'), '&quot; &apos; &lt;
> &');
+    t.equals(escape('" \' < > &', '"\'<>&'), '" \' < > &');
+})
+
+test("Module should not escape random characters", function (t) {
+    t.plan(1);
+
+    t.equals(escape('<[whats up]>', '<]what'), '<[whats up]&gt;');
+})
+
+test("Module should not crash on null or undefined input", function (t) {
+    t.plan(3);
+
+    t.equals((escape("")), "");
+    t.doesNotThrow(function(){escape(null);}, TypeError);
+    t.doesNotThrow(function(){escape(undefined);}, TypeError);
+})

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/7e5c19b8/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 745d99a..302aedb 100644
--- a/package.json
+++ b/package.json
@@ -43,7 +43,8 @@
     "plist": "^1.2.0",
     "q": "^1.4.1",
     "shelljs": "^0.5.3",
-    "xcode": "^0.8.5"
+    "xcode": "^0.8.5",
+    "xml-escape": "^1.1.0"
   },
   "bundledDependencies": [
     "cordova-common",
@@ -52,6 +53,7 @@
     "plist",
     "q",
     "shelljs",
-    "xcode"
+    "xcode",
+    "xml-escape"
   ]
 }

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/7e5c19b8/tests/spec/create.spec.js
----------------------------------------------------------------------
diff --git a/tests/spec/create.spec.js b/tests/spec/create.spec.js
index 4c6e0d1..0791632 100644
--- a/tests/spec/create.spec.js
+++ b/tests/spec/create.spec.js
@@ -102,6 +102,13 @@ describe('create', function() {
         createAndBuild(projectname, projectid);
     });
 
+    it('Test#008 : create project with ascii name, and spaces, ampersand(&)', function()
{
+       var projectname = 'hello & world';
+       var projectid = 'com.test.app7';
+
+       createAndBuild(projectname, projectid);
+    });
+
 });
 
 describe('end-to-end list validation', function(){


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message