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

Commit 8568b20

Browse files
committed
Use isAbsoluteUrl and add passing test for absolute paths
1 parent 5433de5 commit 8568b20

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

src/utils/ExtensionUtils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
26-
/*global define, $, brackets, less */
26+
/*global define, $, brackets, less, PathUtils */
2727

2828
/**
2929
* ExtensionUtils defines utility methods for implementing extensions.
@@ -91,7 +91,7 @@ define(function (require, exports, module) {
9191
rootpath: dir
9292
};
9393

94-
if (url.indexOf("file://") === 0) {
94+
if (PathUtils.isAbsoluteUrl(url)) {
9595
options.currentFileInfo = {
9696
currentDirectory: dir,
9797
entryPath: dir,
@@ -161,7 +161,7 @@ define(function (require, exports, module) {
161161
* @return {!$.Promise} A promise object that is resolved with the contents of the requested file
162162
**/
163163
function loadFile(module, path) {
164-
var url = getModuleUrl(module, path),
164+
var url = PathUtils.isAbsoluteUrl(path) ? path : getModuleUrl(module, path),
165165
promise = $.get(url);
166166

167167
return promise;

test/spec/ExtensionUtils-test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,36 @@ define(function (require, exports, module) {
137137
expect(testWindow.$.contains(testWindow.document, result)).toBeTruthy();
138138
});
139139
});
140+
141+
// putting everything LESS related in 1 test so it runs faster
142+
it("should attach LESS style sheets using absolute url", function () {
143+
var promise, result;
144+
145+
runs(function () {
146+
var indexLocation = testWindow.location.origin + testWindow.location.pathname,
147+
bracketsLocation = indexLocation.substring(0, indexLocation.length - "src/index.html".length),
148+
basicLessLocation = bracketsLocation + "test/spec/ExtensionUtils-test-files/basic.less";
149+
150+
promise = loadStyleSheet(testWindow.document, basicLessLocation);
151+
promise.done(function (style) {
152+
result = style;
153+
});
154+
155+
waitsForDone(promise);
156+
});
157+
158+
runs(function () {
159+
// convert all line endings to platform default
160+
var windowText = FileUtils.translateLineEndings(testWindow.$(result).text()),
161+
lessText = FileUtils.translateLineEndings(LESS_RESULT);
162+
163+
// confirm style sheet contents
164+
expect(windowText).toBe(lessText);
165+
166+
// confirm style is attached to document
167+
expect(testWindow.$.contains(testWindow.document, result)).toBeTruthy();
168+
});
169+
});
140170
});
141171
});
142172
});

0 commit comments

Comments
 (0)