Skip to content

Commit 2cfaa06

Browse files
committed
parser fix for escaped strings
* don't use homegrown 'escapeInternals' function * update various tests
1 parent 0c01b15 commit 2cfaa06

File tree

7 files changed

+80
-12
lines changed

7 files changed

+80
-12
lines changed

lib/parser/pbxproj.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/parser/pbxproj.pegjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ NonQuote
204204
= EscapedQuote / !DoubleQuote char:. { return char }
205205

206206
EscapedQuote
207-
= "\\" DoubleQuote { return '\"' }
207+
= "\\" DoubleQuote { return '\\"' }
208208

209209
LiteralString
210210
= literal:LiteralChar+ { return literal.join('') }

lib/pbxWriter.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ function pbxWriter(contents) {
3838
this.indentLevel = 0;
3939
}
4040

41-
function escapeInternals(str) {
42-
return str.replace(QUOTED, function (orig, middle) {
43-
return f('"%s"', middle.replace(/"/g, '\\"'));
44-
});
45-
}
46-
4741
util.inherits(pbxWriter, EventEmitter);
4842

4943
pbxWriter.prototype.write = function (str) {
@@ -145,9 +139,6 @@ pbxWriter.prototype.writeObject = function (object) {
145139
this.indentLevel--;
146140
this.write("};\n");
147141
} else {
148-
if (QUOTED.test(obj))
149-
obj = escapeInternals(obj);
150-
151142
if (cmt) {
152143
this.write("%s = %s /* %s */;\n", key, obj, cmt)
153144
} else {

test/parser/build-config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var PEG = require('pegjs'),
44
grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'),
55
parser = PEG.buildParser(grammar),
66
rawProj = parser.parse(pbx),
7+
util = require('util'),
78
project = rawProj.project;
89

910
exports['should parse the build config section'] = function (test) {
@@ -18,3 +19,12 @@ exports['should read a decimal value correctly'] = function (test) {
1819
test.strictEqual(debugSettings['IPHONEOS_DEPLOYMENT_TARGET'], '3.0');
1920
test.done();
2021
}
22+
23+
exports['should read an escaped value correctly'] = function (test) {
24+
var xcbConfig = project.objects['XCBuildConfiguration'],
25+
debugSettings = xcbConfig['C01FCF4F08A954540054247B'].buildSettings,
26+
expt = '"\\"$(PHONEGAPLIB)/Classes/JSON\\" \\"$(PHONEGAPLIB)/Classes\\""';
27+
28+
test.strictEqual(debugSettings['USER_HEADER_SEARCH_PATHS'], expt);
29+
test.done();
30+
}

test/parser/header-search.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var PEG = require('pegjs'),
2+
fs = require('fs'),
3+
pbx = fs.readFileSync('test/parser/projects/header-search.pbxproj', 'utf-8'),
4+
grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'),
5+
parser = PEG.buildParser(grammar),
6+
rawProj = parser.parse(pbx),
7+
project = rawProj.project;
8+
9+
exports['should read a decimal value correctly'] = function (test) {
10+
var debug = project.objects['XCBuildConfiguration']['C01FCF4F08A954540054247B'],
11+
hsPaths = debug.buildSettings['HEADER_SEARCH_PATHS'],
12+
expected = '"\\"$(TARGET_BUILD_DIR)/usr/local/lib/include\\""';
13+
14+
test.equal(hsPaths[0], expected);
15+
test.done();
16+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// !$*UTF8*$!
2+
{
3+
archiveVersion = 1;
4+
classes = {
5+
};
6+
objectVersion = 46;
7+
objects = {
8+
/* Begin XCBuildConfiguration section */
9+
C01FCF4F08A954540054247B /* Debug */ = {
10+
isa = XCBuildConfiguration;
11+
baseConfigurationReference = 307D28A1123043350040C0FA /* CordovaBuildSettings.xcconfig */;
12+
buildSettings = {
13+
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
14+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
15+
GCC_C_LANGUAGE_STANDARD = c99;
16+
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
17+
GCC_WARN_ABOUT_RETURN_TYPE = YES;
18+
GCC_WARN_UNUSED_VARIABLE = YES;
19+
HEADER_SEARCH_PATHS = (
20+
"\"$(TARGET_BUILD_DIR)/usr/local/lib/include\"",
21+
"\"$(OBJROOT)/UninstalledProducts/include\"",
22+
"\"$(BUILT_PRODUCTS_DIR)\"",
23+
);
24+
IPHONEOS_DEPLOYMENT_TARGET = 4.2;
25+
OTHER_LDFLAGS = (
26+
"-weak_framework",
27+
CoreFoundation,
28+
"-weak_framework",
29+
UIKit,
30+
"-weak_framework",
31+
AVFoundation,
32+
"-weak_framework",
33+
CoreMedia,
34+
"-weak-lSystem",
35+
"-all_load",
36+
"-Obj-C",
37+
);
38+
SDKROOT = iphoneos;
39+
SKIP_INSTALL = NO;
40+
USER_HEADER_SEARCH_PATHS = "";
41+
};
42+
name = Debug;
43+
};
44+
/* End XCBuildConfiguration section */
45+
};
46+
rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
47+
}

test/pbxWriter.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ function testContentsInDepth(filename, test) {
3333
test.equal(writtenLines.length, contentLines.length);
3434

3535
for (var i=0; i<writtenLines.length; i++) {
36-
test.equal(writtenLines[i], contentLines[i])
36+
test.equal(writtenLines[i], contentLines[i],
37+
'match failed on line ' + (i+1))
3738
}
3839

3940
test.done();
@@ -59,6 +60,9 @@ exports.writeSync = {
5960
'should write out the "build-config" test': function (test) {
6061
testProjectContents('test/parser/projects/build-config.pbxproj', test);
6162
},
63+
'should write out the "header-search" test': function (test) {
64+
testProjectContents('test/parser/projects/header-search.pbxproj', test);
65+
},
6266
'should write out the "nested-object" test': function (test) {
6367
testProjectContents('test/parser/projects/nested-object.pbxproj', test);
6468
},

0 commit comments

Comments
 (0)