Skip to content

Commit

Permalink
Merge pull request adobe#18 from adobe/fixIssue16
Browse files Browse the repository at this point in the history
Fix issue16, proper handling of special charaters in file names
  • Loading branch information
gruehle committed Dec 20, 2011
2 parents f55dddd + 0cf43a5 commit 34837a2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
Binary file modified bin/mac/Brackets.app/Contents/MacOS/Brackets
Binary file not shown.
10 changes: 0 additions & 10 deletions bin/mac/Brackets.app/Contents/Resources/brackets_extensions.js
Expand Up @@ -118,16 +118,6 @@ if (!brackets.fs)
brackets.fs.readdir = function(path, callback) {
native function ReadDir();
var resultString = ReadDir(path);

// File paths can have special characters, so escape them before parsing to JSON
resultString = resultString.replace(/\r/g, "\\r")
.replace(/\n/g, "\\n")
.replace(/\&/g, "\\&")
.replace(/\'/g, "\\'")
.replace(/\t/g, "\\t")
//.replace(/\b/g, "\\b") \\ TODO: leaving this in screws up Brackets launch. I don't know why
.replace(/\f/g, "\\f");

var result = JSON.parse(resultString || '[]');
callback(getLastError(), result);
};
Expand Down
10 changes: 0 additions & 10 deletions src/mac/Resources/brackets_extensions.js
Expand Up @@ -118,16 +118,6 @@ if (!brackets.fs)
brackets.fs.readdir = function(path, callback) {
native function ReadDir();
var resultString = ReadDir(path);

// File paths can have special characters, so escape them before parsing to JSON
resultString = resultString.replace(/\r/g, "\\r")
.replace(/\n/g, "\\n")
.replace(/\&/g, "\\&")
.replace(/\'/g, "\\'")
.replace(/\t/g, "\\t")
//.replace(/\b/g, "\\b") \\ TODO: leaving this in screws up Brackets launch. I don't know why
.replace(/\f/g, "\\f");

var result = JSON.parse(resultString || '[]');
callback(getLastError(), result);
};
Expand Down
36 changes: 33 additions & 3 deletions src/mac/cefclient/brackets_extensions.mm
Expand Up @@ -380,17 +380,47 @@ int ExecuteDeleteFileOrDirectory(const CefV8ValueList& arguments,

return ConvertNSErrorCode(error);
}

// Escapes characters that have special meaning in JSON
void EscapeJSONString(const std::string& str, std::string& result) {
result = "";

for(size_t pos = 0; pos != str.size(); ++pos) {
switch(str[pos]) {
case '\a': result.append("\\a"); break;
case '\b': result.append("\\b"); break;
case '\f': result.append("\\f"); break;
case '\n': result.append("\\n"); break;
case '\r': result.append("\\r"); break;
case '\t': result.append("\\t"); break;
case '\v': result.append("\\v"); break;
// Note: single quotes are OK for JSON
case '\"': result.append("\\\""); break; // double quote
case '\\': result.append("\\\\"); break; // backslash


default: result.append( 1, str[pos]); break;

}
}
}


void NSArrayToJSONString(NSArray* array, std::string& result)
{
{
int numItems = [array count];
std::string escapedStr = "";

result = "[";
std::string item;
for (int i = 0; i < numItems; i++)
{
result += "\"";
result += [[array objectAtIndex:i] UTF8String];
result += "\"";

item = [[array objectAtIndex:i] UTF8String];
EscapeJSONString(item, escapedStr);

result += escapedStr + "\"";

if (i < numItems - 1)
result += ", ";
Expand Down

0 comments on commit 34837a2

Please sign in to comment.