diff --git a/controllers/script.js b/controllers/script.js index 2725892d4..9d35ded2d 100644 --- a/controllers/script.js +++ b/controllers/script.js @@ -151,7 +151,6 @@ var getScriptPageTasks = function (aOptions) { // Show which libraries hosted on the site a script uses if (!script.isLib && script.uses && script.uses.length > 0) { - script.usesLibs = true; script.libs = []; tasks.push(function (aCallback) { Script.find({ @@ -161,6 +160,10 @@ var getScriptPageTasks = function (aOptions) { script.libs = aScriptLibraryList; script.libs = _.map(script.libs, modelParser.parseScript); + + if (script.libs.length > 0) { + script.usesLibs = true; + } aCallback(); }); }); diff --git a/controllers/scriptStorage.js b/controllers/scriptStorage.js index 299f94466..73fbbcc93 100644 --- a/controllers/scriptStorage.js +++ b/controllers/scriptStorage.js @@ -270,11 +270,12 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) { var isLibrary = typeof aMeta === 'string'; var libraries = []; var requires = null; + var match = null; var collaborators = null; - var libraryRegex = new RegExp('^https?:\/\/' + - (isPro ? - 'openuserjs\.org' : 'localhost:8080') + - '\/(?:libs\/src|src\/libs)\/(.+?\/.+?\.js)$', ''); + var rLibrary = new RegExp( + '^(?:(?:(?:https?:)?\/\/' + + (isPro ? 'openuserjs\.org' : 'localhost:8080') + + ')?\/(?:libs\/src|src\/libs)\/)?(.*?)([^\/]*\.js)$', ''); if (!aMeta) { return aCallback(null); } @@ -307,8 +308,16 @@ exports.storeScript = function (aUser, aMeta, aBuf, aCallback, aUpdate) { } requires.forEach(function (aRequire) { - var match = libraryRegex.exec(aRequire); - if (match && match[1]) { libraries.push(match[1]); } + match = rLibrary.exec(aRequire); + if (match) { + if (!match[1]) { + match[1] = aUser.name + '/'; + } + + if (!/\.user\.js$/.test(match[2])) { + libraries.push(match[1] + match[2]); + } + } }); } } else {