@marcel91200 / caddy Mirror · read-only / commits / 2f91b445
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

v2: Make tests work on Windows (#2782)

* file_server: Make tests work on Windows * caddyfile: Fix escaping when character is not escapable We only escape certain characters depending on inside or outside of quotes (mainly newlines and quotes). We don't want everyone to have to escape Windows file paths like C:\\Windows\\... but we can't drop the \ either if it's just C:\Windows\...

Matt Holt committed Oct 15, 2019 at 16:05 UTC 2f91b44587fe487b6a05c1c7e56833247e4b8c79
3 files changed +27 -10
caddyconfig/caddyfile/lexer.go
+5
@@ -153,6 +153,11 @@ func (l *lexer) next() bool {
153 }
154 }
155
156 + if escaped {
157 + val = append(val, '\\')
158 + escaped = false
159 + }
160 +
161 val = append(val, ch)
162 }
163 }
caddyconfig/caddyfile/lexer_test.go
+6
@@ -151,6 +151,12 @@ func TestLexer(t *testing.T) {
151 {Line: 1, Text: `don't\\escape`},
152 },
153 },
154 + {
155 + input: `un\escapable`,
156 + expected: []Token{
157 + {Line: 1, Text: `un\escapable`},
158 + },
159 + },
160 {
161 input: `A "quoted value with line
162 break inside" {
modules/caddyhttp/fileserver/staticfiles_test.go
+16 -10
@@ -16,14 +16,15 @@ package fileserver
16
17 import (
18 "net/url"
19 + "path/filepath"
20 "testing"
21 )
22
23 func TestSanitizedPathJoin(t *testing.T) {
24 // For easy reference:
24 - // %2E = .
25 - // %2F = /
26 - // %5C = \
25 + // %2e = .
26 + // %2f = /
27 + // %5c = \
28 for i, tc := range []struct {
29 inputRoot string
30 inputPath string
@@ -43,12 +44,12 @@ func TestSanitizedPathJoin(t *testing.T) {
44 },
45 {
46 inputPath: "/foo/bar",
46 - expect: "foo/bar",
47 + expect: filepath.Join("foo", "bar"),
48 },
49 {
50 inputRoot: "/a",
51 inputPath: "/foo/bar",
51 - expect: "/a/foo/bar",
52 + expect: filepath.Join("/", "a", "foo", "bar"),
53 },
54 {
55 inputPath: "/foo/../bar",
@@ -57,24 +58,29 @@ func TestSanitizedPathJoin(t *testing.T) {
58 {
59 inputRoot: "/a/b",
60 inputPath: "/foo/../bar",
60 - expect: "/a/b/bar",
61 + expect: filepath.Join("/", "a", "b", "bar"),
62 },
63 {
64 inputRoot: "/a/b",
65 inputPath: "/..%2fbar",
65 - expect: "/a/b/bar",
66 + expect: filepath.Join("/", "a", "b", "bar"),
67 },
68 {
69 inputRoot: "/a/b",
70 inputPath: "/%2e%2e%2fbar",
70 - expect: "/a/b/bar",
71 + expect: filepath.Join("/", "a", "b", "bar"),
72 },
73 {
74 inputRoot: "/a/b",
75 inputPath: "/%2e%2e%2f%2e%2e%2f",
75 - expect: "/a/b",
76 + expect: filepath.Join("/", "a", "b"),
77 },
77 - // TODO: test windows paths... on windows... sigh.
78 + {
79 + inputRoot: "C:\\www",
80 + inputPath: "/foo/bar",
81 + expect: filepath.Join("C:\\www", "foo", "bar"),
82 + },
83 + // TODO: test more windows paths... on windows... sigh.
84 } {
85 // we don't *need* to use an actual parsed URL, but it
86 // adds some authenticity to the tests since real-world