diff --git a/grails-app/taglib/org/grails/plugin/resource/ResourceTagLib.groovy b/grails-app/taglib/org/grails/plugin/resource/ResourceTagLib.groovy index 02a82d3..5a7a9bf 100644 --- a/grails-app/taglib/org/grails/plugin/resource/ResourceTagLib.groovy +++ b/grails-app/taglib/org/grails/plugin/resource/ResourceTagLib.groovy @@ -40,7 +40,7 @@ class ResourceTagLib { } ] - + static writeAttrs( attrs, output) { // Output any remaining user-specified attributes attrs.each { k, v -> @@ -445,7 +445,7 @@ class ResourceTagLib { def stash = { attrs, body -> stashPageFragment(attrs.type, attrs.disposition, body()) } - + protected getModuleByName(name) { def module = grailsResourceProcessor.getModule(name) if (!module) { @@ -485,7 +485,7 @@ class ResourceTagLib { def debugMode = grailsResourceProcessor.isDebugMode(request) for (r in module.resources) { - if (!r.exists() && !r.actualUrl?.contains('://')) { + if (!r.exists() && !URLUtils.isGlobalAbsolute(r.actualUrl)) { throw new IllegalArgumentException("Module [$name] depends on resource [${r.sourceUrl}] but the file cannot be found") } if (log.debugEnabled) { @@ -525,7 +525,7 @@ class ResourceTagLib { } def ctxPath = request.contextPath def uri = attrs.remove('uri') - def abs = uri?.indexOf('://') >= 0 + def abs = URLUtils.isGlobalAbsolute(uri) if (!uri || !abs) { if (uri) { @@ -535,7 +535,7 @@ class ResourceTagLib { // via g.resource attrs.contextPath = ctxPath uri = grailsLinkGenerator.resource(attrs) - abs = uri.contains('://') + abs = URLUtils.isGlobalAbsolute(uri) } } @@ -587,12 +587,13 @@ class ResourceTagLib { } // If the link has to support linkUrl for override, or fall back to the full requested url - // we resolve without query params, but must keep them for linking - def linkUrl = res ? res.linkUrl : contextRelUri + // we resolve without query params, but must keep them for linking + def linkUrl = res ? res.linkUrl : reluri - if (linkUrl.contains('://')) { + def baseUrl = '' // @todo get from config + if (URLUtils.isGlobalAbsolute(linkUrl) || baseUrl) { // @todo do we need to toggle http/https here based on current request protocol? - return [uri:linkUrl, resource:res] + return [uri:baseUrl ? baseUrl+linkUrl : linkUrl, resource:res] } else { // Only apply static prefix if the resource actually has ResourceMeta created for it uri = res ? ctxPath+grailsResourceProcessor.staticUrlPrefix+linkUrl : ctxPath+linkUrl @@ -635,7 +636,7 @@ class ResourceTagLib { def o = new StringBuilder() o << " 0 } - + boolean isDirty() { !originalResource || (originalResource.lastModified() != originalLastMod) @@ -212,7 +212,7 @@ class ResourceMeta { // Hook for when preparation is starting void beginPrepare(grailsResourceProcessor) { def uri = this.sourceUrl - if (!uri.contains('://')) { + if (!URLUtils.isGlobalAbsolute(uri)) { // Delete whatever file may already be there processedFile?.delete() @@ -347,7 +347,7 @@ class ResourceMeta { return null } } - + String getActualUrlParent() { def lastSlash = actualUrl.lastIndexOf('/') if (lastSlash >= 0) { diff --git a/src/groovy/org/grails/plugin/resource/ResourceModule.groovy b/src/groovy/org/grails/plugin/resource/ResourceModule.groovy index 18e9fbd..278b36a 100644 --- a/src/groovy/org/grails/plugin/resource/ResourceModule.groovy +++ b/src/groovy/org/grails/plugin/resource/ResourceModule.groovy @@ -94,7 +94,7 @@ class ResourceModule { ResourceMeta newResourceFromArgs(Map args, svc, boolean singleResourceModule) { def url = args.remove('url') if (url) { - if (!url.contains('://') && !url.startsWith('/')) { + if (!URLUtils.isGlobalAbsolute(url) && !url.startsWith('/')) { url = '/'+url } } diff --git a/src/groovy/org/grails/plugin/resource/URLUtils.groovy b/src/groovy/org/grails/plugin/resource/URLUtils.groovy index 8739bba..ff16406 100644 --- a/src/groovy/org/grails/plugin/resource/URLUtils.groovy +++ b/src/groovy/org/grails/plugin/resource/URLUtils.groovy @@ -30,4 +30,13 @@ class URLUtils { !url.startsWith('#') && !(url.indexOf('://') >= 0) } + + /** + * Works out if url is globally absolute, as in it begins with a protocol + * like http:// or just // + */ + static Boolean isGlobalAbsolute(url) { + url?.indexOf('://') >= 0 || + url?.startsWith('//') + } } \ No newline at end of file