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
6b801b11
Commit
6b801b11
authored
Mar 18, 2016
by
Abiola Ibrahim
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #684 from abiosoft/master
Fix for #659.
parents
717c88ec
04514fb7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
1 deletion
+16
-1
middleware/rewrite/rewrite.go
middleware/rewrite/rewrite.go
+11
-0
middleware/rewrite/rewrite_test.go
middleware/rewrite/rewrite_test.go
+5
-1
No files found.
middleware/rewrite/rewrite.go
View file @
6b801b11
...
@@ -5,6 +5,7 @@ package rewrite
...
@@ -5,6 +5,7 @@ package rewrite
import
(
import
(
"fmt"
"fmt"
"net/http"
"net/http"
"net/url"
"path"
"path"
"path/filepath"
"path/filepath"
"regexp"
"regexp"
...
@@ -165,7 +166,17 @@ func (r *ComplexRule) Rewrite(fs http.FileSystem, req *http.Request) (re Result)
...
@@ -165,7 +166,17 @@ func (r *ComplexRule) Rewrite(fs http.FileSystem, req *http.Request) (re Result)
return
return
default
:
default
:
// set regexp match variables {1}, {2} ...
// set regexp match variables {1}, {2} ...
// url escaped values of ? and #.
q
,
f
:=
url
.
QueryEscape
(
"?"
),
url
.
QueryEscape
(
"#"
)
for
i
:=
1
;
i
<
len
(
matches
);
i
++
{
for
i
:=
1
;
i
<
len
(
matches
);
i
++
{
// Special case of unescaped # and ? by stdlib regexp.
// Reverse the unescape.
if
strings
.
ContainsAny
(
matches
[
i
],
"?#"
)
{
matches
[
i
]
=
strings
.
NewReplacer
(
"?"
,
q
,
"#"
,
f
)
.
Replace
(
matches
[
i
])
}
replacer
.
Set
(
fmt
.
Sprint
(
i
),
matches
[
i
])
replacer
.
Set
(
fmt
.
Sprint
(
i
),
matches
[
i
])
}
}
}
}
...
...
middleware/rewrite/rewrite_test.go
View file @
6b801b11
...
@@ -34,6 +34,7 @@ func TestRewrite(t *testing.T) {
...
@@ -34,6 +34,7 @@ func TestRewrite(t *testing.T) {
{
"/reggrp"
,
`/ad/([0-9]+)([a-z]*)`
,
"/a{1}/{2}"
,
""
},
{
"/reggrp"
,
`/ad/([0-9]+)([a-z]*)`
,
"/a{1}/{2}"
,
""
},
{
"/reg2grp"
,
`(.*)`
,
"/{1}"
,
""
},
{
"/reg2grp"
,
`(.*)`
,
"/{1}"
,
""
},
{
"/reg3grp"
,
`(.*)/(.*)/(.*)`
,
"/{1}{2}{3}"
,
""
},
{
"/reg3grp"
,
`(.*)/(.*)/(.*)`
,
"/{1}{2}{3}"
,
""
},
{
"/hashtest"
,
"(.*)"
,
"/{1}"
,
""
},
}
}
for
_
,
regexpRule
:=
range
regexps
{
for
_
,
regexpRule
:=
range
regexps
{
...
@@ -90,6 +91,9 @@ func TestRewrite(t *testing.T) {
...
@@ -90,6 +91,9 @@ func TestRewrite(t *testing.T) {
{
"/reg2grp/ad/124abc"
,
"/ad/124abc"
},
{
"/reg2grp/ad/124abc"
,
"/ad/124abc"
},
{
"/reg3grp/ad/aa/66"
,
"/adaa66"
},
{
"/reg3grp/ad/aa/66"
,
"/adaa66"
},
{
"/reg3grp/ad612/n1n/ab"
,
"/ad612n1nab"
},
{
"/reg3grp/ad612/n1n/ab"
,
"/ad612n1nab"
},
{
"/hashtest/a%20%23%20test"
,
"/a%20%23%20test"
},
{
"/hashtest/a%20%3F%20test"
,
"/a%20%3F%20test"
},
{
"/hashtest/a%20%3F%23test"
,
"/a%20%3F%23test"
},
}
}
for
i
,
test
:=
range
tests
{
for
i
,
test
:=
range
tests
{
...
@@ -154,6 +158,6 @@ func TestRewrite(t *testing.T) {
...
@@ -154,6 +158,6 @@ func TestRewrite(t *testing.T) {
}
}
func
urlPrinter
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
func
urlPrinter
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
fmt
.
Fprint
f
(
w
,
r
.
URL
.
String
())
fmt
.
Fprint
(
w
,
r
.
URL
.
String
())
return
0
,
nil
return
0
,
nil
}
}
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