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
9fbac10a
Commit
9fbac10a
authored
May 02, 2017
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "rewrite: Raise error if rewrite path does not begin with / #1610 (#1629)"
This reverts commit
e0ed7093
.
parent
6d9783a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
19 deletions
+5
-19
caddyhttp/rewrite/setup.go
caddyhttp/rewrite/setup.go
+2
-12
caddyhttp/rewrite/setup_test.go
caddyhttp/rewrite/setup_test.go
+3
-7
No files found.
caddyhttp/rewrite/setup.go
View file @
9fbac10a
...
...
@@ -76,10 +76,6 @@ func rewriteParse(c *caddy.Controller) ([]httpserver.HandlerConfig, error) {
return
nil
,
c
.
ArgErr
()
}
to
=
strings
.
Join
(
args1
,
" "
)
// ensure rewrite path begins with /
if
!
strings
.
HasPrefix
(
to
,
"/"
)
{
return
nil
,
c
.
Errf
(
"%s:%d - Syntax error: Rewrite path must begin with '/'. Provided: '%s'"
,
c
.
File
(),
c
.
Line
(),
c
.
Val
())
}
case
"ext"
:
args1
:=
c
.
RemainingArgs
()
if
len
(
args1
)
==
0
{
...
...
@@ -94,20 +90,14 @@ func rewriteParse(c *caddy.Controller) ([]httpserver.HandlerConfig, error) {
if
to
==
""
{
return
nil
,
c
.
ArgErr
()
}
if
rule
,
err
=
NewComplexRule
(
base
,
pattern
,
to
,
ext
,
matcher
);
err
!=
nil
{
return
nil
,
err
}
rules
=
append
(
rules
,
rule
)
//
handle case of 2 arguments: "from to"
//
the only unhandled case is 2 and above
default
:
// ensure rewrite path begins with /
topath
:=
strings
.
Join
(
args
[
1
:
],
" "
)
if
!
strings
.
HasPrefix
(
topath
,
"/"
)
{
return
nil
,
c
.
Errf
(
"%s:%d - Syntax error: Rewrite path must begin with '/'. Provided: '%s'"
,
c
.
File
(),
c
.
Line
(),
c
.
Val
())
}
rule
=
NewSimpleRule
(
args
[
0
],
topath
)
rule
=
NewSimpleRule
(
args
[
0
],
strings
.
Join
(
args
[
1
:
],
" "
))
rules
=
append
(
rules
,
rule
)
}
...
...
caddyhttp/rewrite/setup_test.go
View file @
9fbac10a
...
...
@@ -45,19 +45,15 @@ func TestRewriteParse(t *testing.T) {
SimpleRule
{
From
:
"/from"
,
To
:
"/to"
},
}},
{
`rewrite /from /to
rewrite a
/
b`
,
false
,
[]
Rule
{
rewrite a b`
,
false
,
[]
Rule
{
SimpleRule
{
From
:
"/from"
,
To
:
"/to"
},
SimpleRule
{
From
:
"a"
,
To
:
"
/
b"
},
SimpleRule
{
From
:
"a"
,
To
:
"b"
},
}},
{
`rewrite a b`
,
true
,
[]
Rule
{}},
{
`rewrite a`
,
true
,
[]
Rule
{}},
{
`rewrite`
,
true
,
[]
Rule
{}},
{
`rewrite a b c`
,
tru
e
,
[]
Rule
{
{
`rewrite a b c`
,
fals
e
,
[]
Rule
{
SimpleRule
{
From
:
"a"
,
To
:
"b c"
},
}},
{
`rewrite a /b c`
,
false
,
[]
Rule
{
SimpleRule
{
From
:
"a"
,
To
:
"/b c"
},
}},
}
for
i
,
test
:=
range
simpleTests
{
...
...
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