Skip to content

Commit 053d70c

Browse files
Dimitar KerezovKristian D. Dimitrov
authored andcommitted
Fix path/name quotation
Those properties should be surrounded by quotation marks based on appearance of special characters in path and basename properties respectively. They are independent of one another.
1 parent d61c312 commit 053d70c

File tree

2 files changed

+106
-2
lines changed

2 files changed

+106
-2
lines changed

lib/pbxProject.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ var util = require('util'),
2626
fs = require('fs'),
2727
parser = require('./parser/pbxproj'),
2828
plist = require('simple-plist'),
29-
COMMENT_KEY = /_comment$/
29+
COMMENT_KEY = /_comment$/,
30+
NO_SPECIAL_SYMBOLS = /^[a-zA-Z0-9_\.\$]+\.[a-zA-Z]+$/;
3031

3132
function pbxProject(filename) {
3233
if (!(this instanceof pbxProject))
@@ -1534,8 +1535,11 @@ function pbxFileReferenceObj(file) {
15341535
fileObject.path = fileObject.path.replace(/\"/g, "\\\"");
15351536
}
15361537

1537-
if(!file.basename.match(/^[a-zA-Z0-9_\.\$]+\.[a-zA-Z]+$/)) {
1538+
if(!file.basename.match(NO_SPECIAL_SYMBOLS)) {
15381539
fileObject.name = "\"" + fileObject.name + "\"";
1540+
}
1541+
1542+
if(!file.path.match(NO_SPECIAL_SYMBOLS)) {
15391543
fileObject.path = "\"" + fileObject.path + "\"";
15401544
}
15411545

test/pbxProject.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,103 @@ exports['hasFile'] = {
328328
test.done()
329329
}
330330
}
331+
332+
exports['addToPbxFileReferenceSection'] = {
333+
'should not quote name when no special characters present in basename': function (test) {
334+
var newProj = new pbx('.');
335+
newProj.hash = jsonProject,
336+
file = {
337+
uuid: newProj.generateUuid(),
338+
fileRef: newProj.generateUuid(),
339+
isa: 'PBXFileReference',
340+
explicitFileType: 'wrapper.application',
341+
includeInIndex: 0,
342+
basename: "SomeFile.m",
343+
path: "SomePath.m",
344+
sourceTree: 'BUILT_PRODUCTS_DIR'
345+
},
346+
fileRefSection = newProj.pbxFileReferenceSection();
347+
348+
newProj.addToPbxFileReferenceSection(file);
349+
test.equal(fileRefSection[file.fileRef].name, "SomeFile.m");
350+
test.done();
351+
},
352+
'should quote name when special characters present in basename': function (test) {
353+
var newProj = new pbx('.');
354+
newProj.hash = jsonProject,
355+
file = {
356+
uuid: newProj.generateUuid(),
357+
fileRef: newProj.generateUuid(),
358+
isa: 'PBXFileReference',
359+
explicitFileType: 'wrapper.application',
360+
includeInIndex: 0,
361+
basename: "Some File.m",
362+
path: "SomePath.m",
363+
sourceTree: 'BUILT_PRODUCTS_DIR'
364+
},
365+
fileRefSection = newProj.pbxFileReferenceSection();
366+
367+
newProj.addToPbxFileReferenceSection(file);
368+
test.equal(fileRefSection[file.fileRef].name, '"Some File.m"');
369+
test.done();
370+
},
371+
'should not quote path when no special characters present in path': function (test) {
372+
var newProj = new pbx('.');
373+
newProj.hash = jsonProject,
374+
file = {
375+
uuid: newProj.generateUuid(),
376+
fileRef: newProj.generateUuid(),
377+
isa: 'PBXFileReference',
378+
explicitFileType: 'wrapper.application',
379+
includeInIndex: 0,
380+
basename: "SomeFile.m",
381+
path: "SomePath.m",
382+
sourceTree: 'BUILT_PRODUCTS_DIR'
383+
},
384+
fileRefSection = newProj.pbxFileReferenceSection();
385+
386+
newProj.addToPbxFileReferenceSection(file);
387+
test.equal(fileRefSection[file.fileRef].path, "SomePath.m");
388+
test.done();
389+
},
390+
'should quote path when special characters present in path': function (test) {
391+
var newProj = new pbx('.');
392+
newProj.hash = jsonProject,
393+
file = {
394+
uuid: newProj.generateUuid(),
395+
fileRef: newProj.generateUuid(),
396+
isa: 'PBXFileReference',
397+
explicitFileType: 'wrapper.application',
398+
includeInIndex: 0,
399+
basename: "SomeFile.m",
400+
path: "SomeFolder/Some Path.m",
401+
sourceTree: 'BUILT_PRODUCTS_DIR'
402+
},
403+
fileRefSection = newProj.pbxFileReferenceSection();
404+
405+
newProj.addToPbxFileReferenceSection(file);
406+
test.equal(fileRefSection[file.fileRef].path, '"SomeFolder/Some Path.m"');
407+
test.done();
408+
},
409+
'should quote path and name when special characters present in path and basename': function (test) {
410+
var newProj = new pbx('.');
411+
newProj.hash = jsonProject,
412+
file = {
413+
uuid: newProj.generateUuid(),
414+
fileRef: newProj.generateUuid(),
415+
isa: 'PBXFileReference',
416+
explicitFileType: 'wrapper.application',
417+
includeInIndex: 0,
418+
basename: "Some File.m",
419+
path: "SomeFolder/Some Path.m",
420+
sourceTree: 'BUILT_PRODUCTS_DIR'
421+
},
422+
fileRefSection = newProj.pbxFileReferenceSection();
423+
424+
newProj.addToPbxFileReferenceSection(file);
425+
test.equal(fileRefSection[file.fileRef].name, '"Some File.m"');
426+
test.equal(fileRefSection[file.fileRef].path, '"SomeFolder/Some Path.m"');
427+
test.done();
428+
}
429+
}
430+

0 commit comments

Comments
 (0)