Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Added filename validation for Mac #7377

Closed
wants to merge 8 commits into from
18 changes: 16 additions & 2 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ define(function (require, exports, module) {
saveAsDefaultPath,
defaultName,
result = new $.Deferred();

function _doSaveAfterSaveDialog(path) {
var newFile;

Expand Down Expand Up @@ -803,7 +803,21 @@ define(function (require, exports, module) {
FileSystem.showSaveDialog(Strings.SAVE_FILE_AS, saveAsDefaultPath, defaultName, function (err, selectedPath) {
if (!err) {
if (selectedPath) {
_doSaveAfterSaveDialog(selectedPath);
//Get only the filename (without the final slash) and not the rest of the path
var filename = selectedPath.substr(selectedPath.lastIndexOf("/") + 1);
//Validation for file name path for Mac
//If you try to put a slash into the native file dialog on a Mac, it converts it to a colon
//So this regex will catch it
if (/\?|:|\*/.test(filename)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move the _checkForValidFilename from ProjectManager.js to FileUtils.js and then call it from both places since this is basically doing the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually was about to ask that. I'll do that tonight and push it tonight or tomorrow.

Dialogs.showModalDialog(
DefaultDialogs.DIALOG_ID_ERROR,
StringUtils.format(Strings.INVALID_FILENAME_TITLE, Strings.FILE),
StringUtils.format(Strings.INVALID_FILENAME_MESSAGE, "/?:*")
);
result.reject();
} else {
_doSaveAfterSaveDialog(selectedPath);
}
} else {
result.reject(USER_CANCELED);
}
Expand Down
2 changes: 1 addition & 1 deletion src/project/ProjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2287,7 +2287,7 @@ define(function (require, exports, module) {

// Init invalid characters string
if (brackets.platform === "mac") {
_invalidChars = "?*|:";
_invalidChars = "/?:*";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also shouldn't allow the vertical bar | char

} else if (brackets.platform === "linux") {
_invalidChars = "?*|/";
} else {
Expand Down