Skip to content
Open
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 @@ -253,8 +253,8 @@ protected Pattern convertToRegex(String url) {
// For /(*)?+(\.(*))? we want regex: /(.+?)?(?:\.([^/.]+))? (optional, greedy)
// Only apply greedy regex if this logical URL actually includes the greedy token
String processed = urlEnd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: these comments still reference the old regex (.+?). Now that the pattern is [^/]+?, the comments should be updated to match:

// For /(*)+(\.(*))?  we want regex: /([^/]+?)(?:\.([^/.]+))?  (required, greedy)
// For /(*)?+(\.(*))?  we want regex: /([^/]+?)?(?:\.([^/.]+))? (optional, greedy)

.replace("/(*)?(\\.(*))?", "/(.+?)?(?:\\.([^/.]+))?") // Optional greedy: (*)?+
.replace("/(*)(\\.(*))?", "/(.+?)(?:\\.([^/.]+))?"); // Required greedy: (*)+
.replace("/(*)?(\\.(*))?", "/([^/]+?)?(?:\\.([^/.]+))?") // Optional greedy: (*)?+
.replace("/(*)(\\.(*))?", "/([^/]+?)(?:\\.([^/.]+))?"); // Required greedy: (*)+
pattern += processed;
} else {
pattern += urlEnd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,19 @@ class UrlMappingsWithGreedyExtensionSpec extends AbstractUrlMappingsSpec {
urlMappingsHolder.match('/file.name.csv').parameters.format == 'csv'
}

void "Test that greedy parameter does not match across path segments"() {
given: "A URL mapping with required greedy parameter"
def urlMappingsHolder = getUrlMappingsHolder {
"/$id+(.$format)?"(controller: "user", action: "profile")
}

when: "Matching a URL with a path separator"
def info = urlMappingsHolder.match('/9002/show')

then: "The greedy parameter should not match across path segments"
info == null
}

void "Test that UrlMappingData reports greedy extension correctly"() {
given: "A URL mapping with greedy parameter"
def urlMappingsHolder = getUrlMappingsHolder {
Expand Down
Loading