Skip to content
This repository has been archived by the owner on Jun 14, 2018. It is now read-only.

File names with certain characters (e.g. \r) cause readdir() to crash #16

Closed
peterflynn opened this issue Dec 17, 2011 · 3 comments
Closed
Assignees

Comments

@peterflynn
Copy link
Member

Steps to repro:

  1. Open your /Applications folder in Brackets
  2. Expand the folder for any Adobe CS application (e.g. Flash Builder 4, Illustrator CS5, etc.)

Results:
Folder does not expand. "Unexpected token" error is logged to JS console.

Expected:
Folder expands correctly, no error logged.

So here's what's going on: many applications' root folders contain a special file called "Icon\r" (where \r is an actual newline char). When readdir() calls the native method ReadDir() (ExecuteReadDir() in the ObjC source), it gets back JSON with a \r character inside a string literal, which is illegal syntax in JS, and thus its JSON.parse() call fails.

I think the root bug is actually in NSArrayToJSONString(), which should be escaping special characters in strings before spitting them out into the JSON source. We should probably put that functionality in a new utility function so that we can leverage it in other to-JSON conversions.

@peterflynn
Copy link
Member Author

Note: this replaces the original bug report, adobe/brackets#19

@peterflynn
Copy link
Member Author

Here's a simple proof of concept fix... insert the following lines just before the JSON.parse() call in readdir(): (in brackets_extensions.js)

        resultString = resultString.replace(/\n/g, "\\n");
        resultString = resultString.replace(/\r/g, "\\r");

The real fix should be a bit different:

  1. As noted above, it should be pushed down into the central native method NSArrayToJSONString()
  2. For completeness we should probably escape a few other characters, like ", , and maybe \t (even if these can't occur in Mac filenames, they'll probably arise in other circumstances eventually). (If we wanted to be really paranoid there's also \b, \f, and \v too).

@ghost ghost assigned tvoliter Dec 17, 2011
@tvoliter
Copy link
Contributor

Submitted pull request to fix bug

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants