summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcaddyconfig/caddyfile/lexer.go5
-rwxr-xr-xcaddyconfig/caddyfile/lexer_test.go6
-rw-r--r--modules/caddyhttp/fileserver/staticfiles_test.go26
3 files changed, 27 insertions, 10 deletions
diff --git a/caddyconfig/caddyfile/lexer.go b/caddyconfig/caddyfile/lexer.go
index 0ddad0e..687ff90 100755
--- a/caddyconfig/caddyfile/lexer.go
+++ b/caddyconfig/caddyfile/lexer.go
@@ -153,6 +153,11 @@ func (l *lexer) next() bool {
}
}
+ if escaped {
+ val = append(val, '\\')
+ escaped = false
+ }
+
val = append(val, ch)
}
}
diff --git a/caddyconfig/caddyfile/lexer_test.go b/caddyconfig/caddyfile/lexer_test.go
index ce2e147..9105eb5 100755
--- a/caddyconfig/caddyfile/lexer_test.go
+++ b/caddyconfig/caddyfile/lexer_test.go
@@ -152,6 +152,12 @@ func TestLexer(t *testing.T) {
},
},
{
+ input: `un\escapable`,
+ expected: []Token{
+ {Line: 1, Text: `un\escapable`},
+ },
+ },
+ {
input: `A "quoted value with line
break inside" {
foobar
diff --git a/modules/caddyhttp/fileserver/staticfiles_test.go b/modules/caddyhttp/fileserver/staticfiles_test.go
index d381d42..73762c7 100644
--- a/modules/caddyhttp/fileserver/staticfiles_test.go
+++ b/modules/caddyhttp/fileserver/staticfiles_test.go
@@ -16,14 +16,15 @@ package fileserver
import (
"net/url"
+ "path/filepath"
"testing"
)
func TestSanitizedPathJoin(t *testing.T) {
// For easy reference:
- // %2E = .
- // %2F = /
- // %5C = \
+ // %2e = .
+ // %2f = /
+ // %5c = \
for i, tc := range []struct {
inputRoot string
inputPath string
@@ -43,12 +44,12 @@ func TestSanitizedPathJoin(t *testing.T) {
},
{
inputPath: "/foo/bar",
- expect: "foo/bar",
+ expect: filepath.Join("foo", "bar"),
},
{
inputRoot: "/a",
inputPath: "/foo/bar",
- expect: "/a/foo/bar",
+ expect: filepath.Join("/", "a", "foo", "bar"),
},
{
inputPath: "/foo/../bar",
@@ -57,24 +58,29 @@ func TestSanitizedPathJoin(t *testing.T) {
{
inputRoot: "/a/b",
inputPath: "/foo/../bar",
- expect: "/a/b/bar",
+ expect: filepath.Join("/", "a", "b", "bar"),
},
{
inputRoot: "/a/b",
inputPath: "/..%2fbar",
- expect: "/a/b/bar",
+ expect: filepath.Join("/", "a", "b", "bar"),
},
{
inputRoot: "/a/b",
inputPath: "/%2e%2e%2fbar",
- expect: "/a/b/bar",
+ expect: filepath.Join("/", "a", "b", "bar"),
},
{
inputRoot: "/a/b",
inputPath: "/%2e%2e%2f%2e%2e%2f",
- expect: "/a/b",
+ expect: filepath.Join("/", "a", "b"),
},
- // TODO: test windows paths... on windows... sigh.
+ {
+ inputRoot: "C:\\www",
+ inputPath: "/foo/bar",
+ expect: filepath.Join("C:\\www", "foo", "bar"),
+ },
+ // TODO: test more windows paths... on windows... sigh.
} {
// we don't *need* to use an actual parsed URL, but it
// adds some authenticity to the tests since real-world