CB-12250 CB-12409 iOS: Fix bug with escaping properties from plist file
authorNikita Matrosov <v-nimatr@microsoft.com>
Wed, 29 Mar 2017 13:51:08 +0000 (16:51 +0300)
committerSteve Gill <stevengill97@gmail.com>
Sat, 3 Jun 2017 00:36:39 +0000 (17:36 -0700)
 This closes #533

spec/plist-helpers.spec.js [new file with mode: 0644]
src/util/plist-helpers.js

diff --git a/spec/plist-helpers.spec.js b/spec/plist-helpers.spec.js
new file mode 100644 (file)
index 0000000..7b8cdbc
--- /dev/null
@@ -0,0 +1,42 @@
+var plistHelpers = require('../src/util/plist-helpers');
+
+
+describe('prunePLIST', function() {
+    var doc =  {
+        FirstConfigKey: {
+            FirstPreferenceName: '*',
+            SecondPreferenceName: 'a + b',
+            ThirdPreferenceName: 'x-msauth-$(CFBundleIdentifier:rfc1034identifier)'
+        },
+
+        SecondConfigKey: {
+            FirstPreferenceName: 'abc'
+        }
+    };
+
+    var xml = '<dict>' +
+                '<key>FirstPreferenceName</key>' +
+                '<string>*</string>'  +
+                '<key>SecondPreferenceName</key>' +
+                '<string>a + b</string>'  +
+                '<key>ThirdPreferenceName</key>' +
+                '<string>x-msauth-$(CFBundleIdentifier:rfc1034identifier)</string>'  +
+              '</dict>';
+
+    var selector = 'FirstConfigKey';
+
+    it('Test 01: should remove property from plist file using provided selector', function(done) {
+        var pruneStatus = plistHelpers.prunePLIST(doc, xml, selector);
+
+        expect(pruneStatus).toBeTruthy();
+        expect(doc).toEqual(
+            {
+                SecondConfigKey: {
+                    FirstPreferenceName: 'abc'
+                }
+            }
+        );
+
+        done();
+    });
+});
\ No newline at end of file
index 38eb31b..1222fa8 100644 (file)
@@ -84,7 +84,7 @@ function nodeEqual(node1, node2) {
     if (typeof node1 != typeof node2)
         return false;
     else if (typeof node1 == 'string') {
-        node2 = escapeRE(node2).replace(new RegExp('\\$[a-zA-Z0-9-_]+','gm'),'(.*?)');
+        node2 = escapeRE(node2).replace(/\\\$\S+/gm,'(.*?)');
         return new RegExp('^' + node2 + '$').test(node1);
     }
     else {
@@ -97,5 +97,5 @@ function nodeEqual(node1, node2) {
 
 // escape string for use in regex
 function escapeRE(str) {
-    return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '$&');
+    return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
 }