Skip to content

Commit 9904125

Browse files
author
Dimitar Kerezov
committed
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 1dc527e commit 9904125

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

lib/pbxProject.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,9 @@ function pbxFileReferenceObj(file) {
719719

720720
if(!file.basename.match(/^[a-zA-Z0-9_\.\$]+\.[a-zA-Z]+$/)) {
721721
obj.name = "\"" + obj.name + "\"";
722+
}
723+
724+
if(!file.path.match(/^[a-zA-Z0-9_\.\$]+\.[a-zA-Z]+$/)) {
722725
obj.path = "\"" + obj.path + "\"";
723726
}
724727

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)