Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
5e467883
Commit
5e467883
authored
May 02, 2017
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
httpserver: Base path of "/" matches all paths, even empty ones
Fixes #1645
parent
9fbac10a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
6 deletions
+73
-6
caddyhttp/httpserver/path.go
caddyhttp/httpserver/path.go
+11
-5
caddyhttp/httpserver/path_test.go
caddyhttp/httpserver/path_test.go
+61
-0
caddyhttp/httpserver/tplcontext_test.go
caddyhttp/httpserver/tplcontext_test.go
+1
-1
No files found.
caddyhttp/httpserver/path.go
View file @
5e467883
...
...
@@ -5,19 +5,25 @@ import (
"strings"
)
// Path represents a URI path.
// Path represents a URI path. It should usually be
// set to the value of a request path.
type
Path
string
// Matches checks to see if other matches p.
// Matches checks to see if base matches p. The correct
// usage of this method sets p as the request path, and
// base as a Caddyfile (user-defined) rule path.
//
// Path matching will probably not always be a direct
// comparison; this method assures that paths can be
// easily and consistently matched.
func
(
p
Path
)
Matches
(
other
string
)
bool
{
func
(
p
Path
)
Matches
(
base
string
)
bool
{
if
base
==
"/"
{
return
true
}
if
CaseSensitivePath
{
return
strings
.
HasPrefix
(
string
(
p
),
other
)
return
strings
.
HasPrefix
(
string
(
p
),
base
)
}
return
strings
.
HasPrefix
(
strings
.
ToLower
(
string
(
p
)),
strings
.
ToLower
(
other
))
return
strings
.
HasPrefix
(
strings
.
ToLower
(
string
(
p
)),
strings
.
ToLower
(
base
))
}
// PathMatcher is a Path RequestMatcher.
...
...
caddyhttp/httpserver/path_test.go
0 → 100644
View file @
5e467883
package
httpserver
import
"testing"
func
TestPathMatches
(
t
*
testing
.
T
)
{
for
i
,
testcase
:=
range
[]
struct
{
reqPath
Path
rulePath
string
shouldMatch
bool
caseInsensitive
bool
}{
{
reqPath
:
"/"
,
rulePath
:
"/"
,
shouldMatch
:
true
,
},
{
reqPath
:
"/foo/bar"
,
rulePath
:
"/foo"
,
shouldMatch
:
true
,
},
{
reqPath
:
"/foobar"
,
rulePath
:
"/foo/"
,
shouldMatch
:
false
,
},
{
reqPath
:
"/foobar"
,
rulePath
:
"/foo/bar"
,
shouldMatch
:
false
,
},
{
reqPath
:
"/Foobar"
,
rulePath
:
"/Foo"
,
shouldMatch
:
true
,
},
{
reqPath
:
"/FooBar"
,
rulePath
:
"/Foo"
,
shouldMatch
:
true
,
},
{
reqPath
:
"/foobar"
,
rulePath
:
"/FooBar"
,
shouldMatch
:
true
,
caseInsensitive
:
true
,
},
{
reqPath
:
""
,
rulePath
:
"/"
,
// a lone forward slash means to match all requests (see issue #1645)
shouldMatch
:
true
,
},
}
{
CaseSensitivePath
=
!
testcase
.
caseInsensitive
if
got
,
want
:=
testcase
.
reqPath
.
Matches
(
testcase
.
rulePath
),
testcase
.
shouldMatch
;
got
!=
want
{
t
.
Errorf
(
"Test %d: For request path '%s' and other path '%s': expected %v, got %v"
,
i
,
testcase
.
reqPath
,
testcase
.
rulePath
,
want
,
got
)
}
}
}
caddyhttp/httpserver/tplcontext_test.go
View file @
5e467883
...
...
@@ -497,7 +497,7 @@ func TestMethod(t *testing.T) {
}
func
TestPathMatches
(
t
*
testing
.
T
)
{
func
Test
Context
PathMatches
(
t
*
testing
.
T
)
{
context
:=
getContextOrFail
(
t
)
tests
:=
[]
struct
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment