Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public Decorator getNamedDecorator(HttpServletRequest request, String name, bool

View view;
try {
view = viewResolver.resolveViewName(GrailsResourceUtils.appendPiecesForUri(LAYOUTS_PATH, name),
view = viewResolver.resolveViewName(GrailsResourceUtils.cleanPath(GrailsResourceUtils.appendPiecesForUri(LAYOUTS_PATH, name)),
request.getLocale());
// it's only possible to check that GroovyPageView exists
if (viewMustExist && !(view instanceof AbstractGrailsView)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.grails.web.sitemesh

import org.grails.web.servlet.view.GrailsViewResolver
import org.springframework.mock.web.MockHttpServletRequest
import spock.lang.Issue
import spock.lang.Specification
import spock.lang.Unroll
import javax.servlet.http.HttpServletRequest

/**
* @author Colin Harrington
*/
class GroovyPageLayoutFinderSpec extends Specification {
@Issue("https://github.com/grails/grails-core/issues/10371")
@Unroll("Layout name mapping: #layoutName => #expectedPath")
void "testing layout name resolution"() {
given:
GroovyPageLayoutFinder layoutFinder = new GroovyPageLayoutFinder()
HttpServletRequest request = new MockHttpServletRequest()
layoutFinder.viewResolver = Mock(GrailsViewResolver)
when:
layoutFinder.getNamedDecorator(request, layoutName, false)

then:
1 * layoutFinder.viewResolver.resolveViewName(expectedPath, Locale.ENGLISH)
notThrown(Exception)

where:
layoutName | expectedPath
"foo" | "/layouts/foo"
"foo/bar" | "/layouts/foo/bar"
"../foo" | "/foo"
"../foo/bar" | "/foo/bar"
"../../foo" | "/../foo"
"../foo/../../bar" | "/../bar"
"foo/../../bar" | "/bar"
}
}