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

Fix #4333 (Files incorrectly identified as plain text if folder's name has got the "#" char) #4379

Merged
merged 13 commits into from
Jul 16, 2013
Merged
2 changes: 1 addition & 1 deletion src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global require, define, brackets: true, $, PathUtils, window, navigator, Mustache */
/*global require, define, brackets: true, $, window, navigator, Mustache */

require.config({
paths: {
Expand Down
2 changes: 1 addition & 1 deletion src/document/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $, PathUtils */
/*global define, $ */

define(function (require, exports, module) {
"use strict";
Expand Down
12 changes: 4 additions & 8 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, regexp: true */
/*global define, $, brackets, PathUtils, window */
/*global define, $, brackets, window */

define(function (require, exports, module) {
"use strict";

require("thirdparty/path-utils/path-utils.min");

// Load dependent modules
var AppInit = require("utils/AppInit"),
CommandManager = require("command/CommandManager"),
Expand Down Expand Up @@ -246,9 +244,7 @@ define(function (require, exports, module) {

doOpen(paths[paths.length - 1], silent)
.done(function (doc) {
var url = PathUtils.parseUrl(doc.file.fullPath);
//reconstruct the url but use the directory and stop there
_defaultOpenDialogFullPath = url.protocol + url.doubleSlash + url.authority + url.directory;
_defaultOpenDialogFullPath = FileUtils.getDirectoryPath(doc.file.fullPath);

DocumentManager.addToWorkingSet(doc.file);
})
Expand Down Expand Up @@ -666,7 +662,7 @@ define(function (require, exports, module) {
} else {
saveAsDefaultPath = FileUtils.getDirectoryPath(fullPath);
}
defaultName = PathUtils.parseUrl(fullPath).filename;
defaultName = FileUtils.getBaseName(fullPath);
NativeFileSystem.showSaveDialog(Strings.SAVE_FILE_AS, saveAsDefaultPath, defaultName,
_doSaveAfterSaveDialog,
function (error) {
Expand Down Expand Up @@ -818,7 +814,7 @@ define(function (require, exports, module) {

if (doc && doc.isDirty) {
// Document is dirty: prompt to save changes before closing
var filename = PathUtils.parseUrl(doc.file.fullPath).filename;
var filename = FileUtils.getBaseName(doc.file.fullPath);

Dialogs.showModalDialog(
DefaultDialogs.DIALOG_ID_SAVE_CLOSE,
Expand Down
2 changes: 1 addition & 1 deletion src/document/DocumentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $, PathUtils */
/*global define, $ */

/**
* DocumentManager maintains a list of currently 'open' Documents. It also owns the list of files in
Expand Down
4 changes: 1 addition & 3 deletions src/extensibility/InstallExtensionDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
*/

/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, window, $, brackets, PathUtils, Mustache, document */
/*global define, window, $, brackets, Mustache, document */
/*unittests: Install Extension Dialog*/

define(function (require, exports, module) {
"use strict";

require("thirdparty/path-utils/path-utils.min");

var Dialogs = require("widgets/Dialogs"),
StringUtils = require("utils/StringUtils"),
Strings = require("strings"),
Expand Down
5 changes: 3 additions & 2 deletions src/extensions/default/QuickView/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, brackets, $, window, PathUtils, CodeMirror */
/*global define, brackets, $, window, CodeMirror */

define(function (require, exports, module) {
"use strict";
Expand All @@ -33,6 +33,7 @@ define(function (require, exports, module) {
DocumentManager = brackets.getModule("document/DocumentManager"),
EditorManager = brackets.getModule("editor/EditorManager"),
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
FileUtils = brackets.getModule("file/FileUtils"),
Menus = brackets.getModule("command/Menus"),
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
Strings = brackets.getModule("strings"),
Expand Down Expand Up @@ -411,7 +412,7 @@ define(function (require, exports, module) {
if (PathUtils.isAbsoluteUrl(tokenString)) {
imgPath = tokenString;
} else {
imgPath = "file:///" + docPath.substr(0, docPath.lastIndexOf("/") + 1) + tokenString;
imgPath = "file:///" + FileUtils.getDirectoryPath(docPath) + tokenString;
}

if (urlMatch) {
Expand Down
8 changes: 2 additions & 6 deletions src/extensions/default/UrlCodeHints/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ define(function (require, exports, module) {
CSSUtils = brackets.getModule("language/CSSUtils"),
DocumentManager = brackets.getModule("document/DocumentManager"),
EditorManager = brackets.getModule("editor/EditorManager"),
FileUtils = brackets.getModule("file/FileUtils"),
HTMLUtils = brackets.getModule("language/HTMLUtils"),
NativeFileSystem = brackets.getModule("file/NativeFileSystem").NativeFileSystem,
ProjectManager = brackets.getModule("project/ProjectManager"),
Expand Down Expand Up @@ -69,12 +70,7 @@ define(function (require, exports, module) {
return result;
}

var docUrl = window.PathUtils.parseUrl(doc.file.fullPath);
if (!docUrl) {
return result;
}

var docDir = docUrl.domain + docUrl.directory;
var docDir = FileUtils.getDirectoryPath(doc.file.fullPath);

// get relative path from query string
// TODO: handle site-root relative
Expand Down
37 changes: 35 additions & 2 deletions src/file/FileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ define(function (require, exports, module) {

var NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem,
NativeFileError = require("file/NativeFileError"),
LanguageManager = require("language/LanguageManager"),
PerfUtils = require("utils/PerfUtils"),
Dialogs = require("widgets/Dialogs"),
DefaultDialogs = require("widgets/DefaultDialogs"),
Expand Down Expand Up @@ -365,7 +364,39 @@ define(function (require, exports, module) {
function getDirectoryPath(fullPath) {
return fullPath.substr(0, fullPath.lastIndexOf("/") + 1);
}


/**
* Get the base name of a file or a directory.
* @param {string} full path to a file or directory
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to add fullPath right after {string}.

* @return {string} Returns the base name of a file or the name of a
* directory
*/
function getBaseName(fullPath) {
fullPath = canonicalizeFolderPath(fullPath);
return fullPath.substr(fullPath.lastIndexOf("/") + 1);
}

/**
* Get the filename extension.
*
* @param {string} full path to a file or directory
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to add fullPath right after {string}.

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'll fix a couple of other places where the param name is omitted as well.

* @return {string} Returns the extension of a filename or empty string if
* the argument is a directory
Copy link
Contributor

Choose a reason for hiding this comment

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

Append or a filename with no extension. to this line so that we have more accurate description.

*/
function getFilenameExtension(fullPath) {
var baseName = getBaseName(fullPath),
idx;

idx = baseName.lastIndexOf(".");
Copy link
Contributor

Choose a reason for hiding this comment

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

Combine this with its declaration above just like the way you declare baseName and immediately assign a value.


if (idx === -1) {
return "";
} else {
return baseName.substr(idx);
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to wrap this return statement with else { ... }.

}
}


// Define public API
exports.LINE_ENDINGS_CRLF = LINE_ENDINGS_CRLF;
exports.LINE_ENDINGS_LF = LINE_ENDINGS_LF;
Expand All @@ -386,4 +417,6 @@ define(function (require, exports, module) {
exports.isStaticHtmlFileExt = isStaticHtmlFileExt;
exports.isServerHtmlFileExt = isServerHtmlFileExt;
exports.getDirectoryPath = getDirectoryPath;
exports.getBaseName = getBaseName;
exports.getFilenameExtension = getFilenameExtension;
});
5 changes: 3 additions & 2 deletions src/language/JSUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, PathUtils, CodeMirror */
/*global define, $, brackets, CodeMirror */

/**
* Set of utilities for simple parsing of JS text.
Expand All @@ -34,6 +34,7 @@ define(function (require, exports, module) {
var Async = require("utils/Async"),
DocumentManager = require("document/DocumentManager"),
ChangedDocumentTracker = require("document/ChangedDocumentTracker"),
FileUtils = require("file/FileUtils"),
NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem,
CollectionUtils = require("utils/CollectionUtils"),
PerfUtils = require("utils/PerfUtils"),
Expand Down Expand Up @@ -378,7 +379,7 @@ define(function (require, exports, module) {
if (!keepAllFiles) {
// Filter fileInfos for .js files
jsFiles = fileInfos.filter(function (fileInfo) {
return (/^\.js/i).test(PathUtils.filenameExtension(fileInfo.fullPath));
return (/^\.js/i).test(FileUtils.getFilenameExtension(fileInfo.fullPath));
});
} else {
jsFiles = fileInfos;
Expand Down
9 changes: 5 additions & 4 deletions src/language/LanguageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $, CodeMirror, PathUtils */
/*global define, $, CodeMirror */

/**
* LanguageManager provides access to the languages supported by Brackets
Expand Down Expand Up @@ -103,7 +103,8 @@ define(function (require, exports, module) {

// Dependencies
var Async = require("utils/Async"),
_defaultLanguagesJSON = require("text!language/languages.json");
_defaultLanguagesJSON = require("text!language/languages.json"),
FileUtils = require("file/FileUtils");
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: can you swap the order of this line with the one above? FileUtils and Async are the names of the external modules that use camel case and should be grouped together while the other one is a local variable.



// State
Expand Down Expand Up @@ -187,11 +188,11 @@ define(function (require, exports, module) {
* @return {Language} The language for the provided file type or the fallback language
*/
function getLanguageForPath(path) {
var fileName = PathUtils.filename(path).toLowerCase(),
var fileName = FileUtils.getBaseName(path).toLowerCase(),
language = _fileNameToLanguageMap[fileName],
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Please align = in these two lines just like before your changes.

extension,
parts;

// If no language was found for the file name, use the file extension instead
if (!language) {
// Split the file name into parts:
Expand Down
8 changes: 4 additions & 4 deletions src/project/FileIndexManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, PathUtils */
/*global define, $, brackets */

/*
* Manages a collection of FileIndexes where each index maintains a list of information about
Expand All @@ -41,6 +41,7 @@ define(function (require, exports, module) {

var PerfUtils = require("utils/PerfUtils"),
ProjectManager = require("project/ProjectManager"),
FileUtils = require("file/FileUtils"),
Dialogs = require("widgets/Dialogs"),
DefaultDialogs = require("widgets/DefaultDialogs"),
CollectionUtils = require("utils/CollectionUtils"),
Expand Down Expand Up @@ -406,8 +407,7 @@ define(function (require, exports, module) {
_addIndex(
"css",
function (entry) {
var filename = entry.name;
return PathUtils.filenameExtension(filename) === ".css";
return FileUtils.getFilenameExtension(entry.name) === ".css";
}
);

Expand All @@ -431,4 +431,4 @@ define(function (require, exports, module) {
exports.getFilenameMatches = getFilenameMatches;


});
});
2 changes: 1 addition & 1 deletion src/search/FindInFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $, PathUtils, window, Mustache */
/*global define, $, window, Mustache */

/*
* Adds a "find in files" command to allow the user to find all occurances of a string in all files in
Expand Down
2 changes: 1 addition & 1 deletion test/SpecRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
/*global require, define, $, beforeEach, afterEach, jasmine, brackets, PathUtils */
/*global require, define, $, beforeEach, afterEach, jasmine, brackets */

// Set the baseUrl to brackets/src
require.config({
Expand Down
14 changes: 9 additions & 5 deletions test/spec/CSSUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,32 +515,35 @@ define(function (require, exports, module) {
});

describe("find correct positions of selectors", function () {
var selectors;

selectors = CSSUtils.extractAllSelectors(selectorPositionsTestCss);

it("should find selector positions when whitespace between selector and '{'", function () {
var selectors = CSSUtils.extractAllSelectors(selectorPositionsTestCss);
expect([selectors[0].selectorStartChar, selectors[0].selectorEndChar]).toEqual([0, 3]);
});

it("should find selector positions when no whitespace between selector and '{'", function () {
var selectors = CSSUtils.extractAllSelectors(selectorPositionsTestCss);
expect([selectors[1].selectorStartChar, selectors[1].selectorEndChar]).toEqual([0, 3]);
});

it("should find selector positions when '{' on the next line", function () {
var selectors = CSSUtils.extractAllSelectors(selectorPositionsTestCss);
expect([selectors[2].selectorStartChar, selectors[2].selectorEndChar]).toEqual([0, 3]);
});

it("should find selector positions when '{' on the next line and selector is indented", function () {
var selectors = CSSUtils.extractAllSelectors(selectorPositionsTestCss);
expect([selectors[3].selectorStartChar, selectors[3].selectorEndChar]).toEqual([4, 7]);
});

it("should find selector positions when '{' on the next line and selector is indented with tabs", function () {
var selectors = CSSUtils.extractAllSelectors(selectorPositionsTestCss);
expect([selectors[4].selectorStartChar, selectors[4].selectorEndChar]).toEqual([1, 4]);
});

it("should find selector positions in a selector group when '{' on the next line", function () {
var expected = [0, 2, 4, 6, 8, 10],
var selectors = CSSUtils.extractAllSelectors(selectorPositionsTestCss),
expected = [0, 2, 4, 6, 8, 10],
result = [
selectors[5].selectorStartChar, selectors[5].selectorEndChar,
selectors[6].selectorStartChar, selectors[6].selectorEndChar,
Expand All @@ -551,7 +554,8 @@ define(function (require, exports, module) {
});

it("should find selector positions in a selector group when '{' on the next line and selector group is indented", function () {
var expected = [4, 6, 8, 10, 12, 14],
var selectors = CSSUtils.extractAllSelectors(selectorPositionsTestCss),
expected = [4, 6, 8, 10, 12, 14],
result = [
selectors[8].selectorStartChar, selectors[8].selectorEndChar,
selectors[9].selectorStartChar, selectors[9].selectorEndChar,
Expand Down
12 changes: 9 additions & 3 deletions test/spec/Editor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,19 @@ define(function (require, exports, module) {

it("should switch to the HTML mode for files ending in .html", function () {
// verify editor content
var mode = LanguageManager.getLanguageForPath("file:///only/testing/the/path.html").getMode();
var mode = LanguageManager.getLanguageForPath("c:/only/testing/the/path.html").getMode();
expect(mode).toSpecifyModeNamed("text/x-brackets-html");
});

it("should switch modes even if the url has a query string", function () {
it("should switch modes for UNIX absolute path", function () {
// verify editor content
var mode = LanguageManager.getLanguageForPath("http://only.org/testing/the/path.css?v=2").getMode();
var mode = LanguageManager.getLanguageForPath("/only/testing/the/path.css").getMode();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a hypothetical test case. LanguageManager is used strictly to operate on local files. I think it was inspired by the fact that PathUtils was used to parse the file path in the first place.

expect(mode).toSpecifyModeNamed(langNames.css.mode);
});

it("should switch modes for relative path", function () {
// verify editor content
var mode = LanguageManager.getLanguageForPath("only/testing/the/path.css").getMode();
expect(mode).toSpecifyModeNamed(langNames.css.mode);
});

Expand Down
Loading