Skip to content

Commit 0f9ab43

Browse files
FatmeFatme
Fatme
authored and
Fatme
committed
Merge pull request #2 from Mitko-Kerezov/kerezov/fix-path-name-quotation
Fix path/name quotation
2 parents e1f2a36 + f879ed0 commit 0f9ab43

File tree

3 files changed

+107
-3
lines changed

3 files changed

+107
-3
lines changed

lib/pbxProject.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ var util = require('util'),
88
pbxFile = require('./pbxFile'),
99
fs = require('fs'),
1010
parser = require('./parser/pbxproj'),
11-
COMMENT_KEY = /_comment$/
11+
COMMENT_KEY = /_comment$/,
12+
NO_SPECIAL_SYMBOLS = /^[a-zA-Z0-9_\.\$]+\.[a-zA-Z]+$/;
1213

1314
function pbxProject(filename) {
1415
if (!(this instanceof pbxProject))
@@ -717,8 +718,11 @@ function pbxFileReferenceObj(file) {
717718
obj.path = obj.path.replace(/\"/g, "\\\"");
718719
}
719720

720-
if(!file.basename.match(/^[a-zA-Z0-9_\.\$]+\.[a-zA-Z]+$/)) {
721+
if(!file.basename.match(NO_SPECIAL_SYMBOLS)) {
721722
obj.name = "\"" + obj.name + "\"";
723+
}
724+
725+
if(!file.path.match(NO_SPECIAL_SYMBOLS)) {
722726
obj.path = "\"" + obj.path + "\"";
723727
}
724728

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"node-uuid":"1.3.3"
1616
},
1717
"devDependencies": {
18-
"nodeunit":"0.6.4"
18+
"nodeunit":"0.9.0"
1919
},
2020
"scripts": {
2121
"test": "node_modules/.bin/nodeunit test/parser test"

test/pbxProject.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,103 @@ exports['hasFile'] = {
202202
test.done()
203203
}
204204
}
205+
206+
exports['addToPbxFileReferenceSection'] = {
207+
'should not quote name when no special characters present in basename': function (test) {
208+
var newProj = new pbx('.');
209+
newProj.hash = jsonProject,
210+
file = {
211+
uuid: newProj.generateUuid(),
212+
fileRef: newProj.generateUuid(),
213+
isa: 'PBXFileReference',
214+
explicitFileType: 'wrapper.application',
215+
includeInIndex: 0,
216+
basename: "SomeFile.m",
217+
path: "SomePath.m",
218+
sourceTree: 'BUILT_PRODUCTS_DIR'
219+
},
220+
fileRefSection = newProj.pbxFileReferenceSection();
221+
222+
newProj.addToPbxFileReferenceSection(file);
223+
test.equal(fileRefSection[file.fileRef].name, "SomeFile.m");
224+
test.done();
225+
},
226+
'should quote name when special characters present in basename': function (test) {
227+
var newProj = new pbx('.');
228+
newProj.hash = jsonProject,
229+
file = {
230+
uuid: newProj.generateUuid(),
231+
fileRef: newProj.generateUuid(),
232+
isa: 'PBXFileReference',
233+
explicitFileType: 'wrapper.application',
234+
includeInIndex: 0,
235+
basename: "Some File.m",
236+
path: "SomePath.m",
237+
sourceTree: 'BUILT_PRODUCTS_DIR'
238+
},
239+
fileRefSection = newProj.pbxFileReferenceSection();
240+
241+
newProj.addToPbxFileReferenceSection(file);
242+
test.equal(fileRefSection[file.fileRef].name, '"Some File.m"');
243+
test.done();
244+
},
245+
'should not quote path when no special characters present in path': function (test) {
246+
var newProj = new pbx('.');
247+
newProj.hash = jsonProject,
248+
file = {
249+
uuid: newProj.generateUuid(),
250+
fileRef: newProj.generateUuid(),
251+
isa: 'PBXFileReference',
252+
explicitFileType: 'wrapper.application',
253+
includeInIndex: 0,
254+
basename: "SomeFile.m",
255+
path: "SomePath.m",
256+
sourceTree: 'BUILT_PRODUCTS_DIR'
257+
},
258+
fileRefSection = newProj.pbxFileReferenceSection();
259+
260+
newProj.addToPbxFileReferenceSection(file);
261+
test.equal(fileRefSection[file.fileRef].path, "SomePath.m");
262+
test.done();
263+
},
264+
'should quote path when special characters present in path': function (test) {
265+
var newProj = new pbx('.');
266+
newProj.hash = jsonProject,
267+
file = {
268+
uuid: newProj.generateUuid(),
269+
fileRef: newProj.generateUuid(),
270+
isa: 'PBXFileReference',
271+
explicitFileType: 'wrapper.application',
272+
includeInIndex: 0,
273+
basename: "SomeFile.m",
274+
path: "SomeFolder/Some Path.m",
275+
sourceTree: 'BUILT_PRODUCTS_DIR'
276+
},
277+
fileRefSection = newProj.pbxFileReferenceSection();
278+
279+
newProj.addToPbxFileReferenceSection(file);
280+
test.equal(fileRefSection[file.fileRef].path, '"SomeFolder/Some Path.m"');
281+
test.done();
282+
},
283+
'should quote path and name when special characters present in path and basename': function (test) {
284+
var newProj = new pbx('.');
285+
newProj.hash = jsonProject,
286+
file = {
287+
uuid: newProj.generateUuid(),
288+
fileRef: newProj.generateUuid(),
289+
isa: 'PBXFileReference',
290+
explicitFileType: 'wrapper.application',
291+
includeInIndex: 0,
292+
basename: "Some File.m",
293+
path: "SomeFolder/Some Path.m",
294+
sourceTree: 'BUILT_PRODUCTS_DIR'
295+
},
296+
fileRefSection = newProj.pbxFileReferenceSection();
297+
298+
newProj.addToPbxFileReferenceSection(file);
299+
test.equal(fileRefSection[file.fileRef].name, '"Some File.m"');
300+
test.equal(fileRefSection[file.fileRef].path, '"SomeFolder/Some Path.m"');
301+
test.done();
302+
}
303+
}
304+

0 commit comments

Comments
 (0)