diff --git a/src/core/PaperScope.js b/src/core/PaperScope.js index de3fec8c..343cf0e0 100644 --- a/src/core/PaperScope.js +++ b/src/core/PaperScope.js @@ -292,12 +292,6 @@ var PaperScope = Base.extend(/** @lends PaperScope# */{ delete PaperScope._scopes[this._id]; }, - resolvePath: function(url) { - // On Node.js, resolve relative URLs to local files: - return url && this.agent.node && !/^[a-z]+:/i.test(url) - ? 'file://' + require('path').resolve(url) : url; - }, - statics: new function() { // Produces helpers to e.g. check for both 'canvas' and // 'data-paper-canvas' attributes: diff --git a/src/item/Raster.js b/src/item/Raster.js index c35c6198..018c34e2 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -371,7 +371,7 @@ var Raster = Item.extend(/** @lends Raster# */{ setSource: function(src) { var image = new window.Image(), crossOrigin = this._crossOrigin; - image.src = paper.resolvePath(src); + image.src = src; if (crossOrigin) image.crossOrigin = crossOrigin; this.setImage(image); diff --git a/src/net/Http.js b/src/net/Http.js index 26ec7827..e5a304af 100644 --- a/src/net/Http.js +++ b/src/net/Http.js @@ -14,8 +14,7 @@ var Http = { request: function(options) { // Code borrowed from Coffee Script and extended: var xhr = new window.XMLHttpRequest(); - xhr.open((options.method || 'get').toUpperCase(), - paper.resolvePath(options.url), + xhr.open((options.method || 'get').toUpperCase(), options.url, Base.pick(options.async, true)); if (options.mimeType) xhr.overrideMimeType(options.mimeType); diff --git a/src/node/window.js b/src/node/window.js index f3700fd1..3ea2cce3 100644 --- a/src/node/window.js +++ b/src/node/window.js @@ -18,10 +18,9 @@ var jsdom = require('jsdom'); // Create our document and window objects through jsdom. /* global document:true, window:true */ var document = jsdom.jsdom('', { - // Give the resulting document the same origins as the XMLHttpRequest - // objects for local files, so files can be loaded locally without CORS. - // TODO: Find a proper solution instead of this hack. - url: 'file://', + // Use the current working directory as the document's origin, so + // requests to local files work correctly with CORS. + url: 'file://' + process.cwd() + '/', features: { FetchExternalResources: ['img', 'script'] } diff --git a/test/tests/Raster.js b/test/tests/Raster.js index 7e8d2e60..8bb074bf 100644 --- a/test/tests/Raster.js +++ b/test/tests/Raster.js @@ -60,6 +60,10 @@ test('Create a raster from a dom image', function(assert) { equals(raster.size, new Size(146, 146), true); document.body.removeChild(img); done(); + }, + error: function() { + pushFailure('Loading from a valid data URL should not give an error.'); + done(); } }); }); @@ -82,6 +86,10 @@ test('Create a raster from a dom id', function(assert) { equals(raster.size, new Size(146, 146), true); document.body.removeChild(img); done(); + }, + error: function() { + pushFailure('Loading from a valid data URL should not give an error.'); + done(); } }); });