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
caddyfile: Support backticks as quotes (closes #2591) (#3242)
Matt Holt committed
May 5, 2020 at 12:27 UTC
52305618dfc4289e5a3cfcf848450500ef8fa21c
2 files changed
+44
-5
caddyconfig/caddyfile/lexer.go
+12
-5
@@ -73,7 +73,7 @@ func (l *lexer) load(input io.Reader) error {
73
// a token was loaded; false otherwise.
74
func (l *lexer) next() bool {
75
var val []rune
76
- var comment, quoted, escaped bool
76
+ var comment, quoted, btQuoted, escaped bool
77
78
makeToken := func() bool {
79
l.token.Text = string(val)
@@ -92,13 +92,13 @@ func (l *lexer) next() bool {
92
panic(err)
93
}
94
95
- if !escaped && ch == '\\' {
95
+ if !escaped && !btQuoted && ch == '\\' {
96
escaped = true
97
continue
98
}
99
100
- if quoted {
101
- if escaped {
100
+ if quoted || btQuoted {
101
+ if quoted && escaped {
102
// all is literal in quoted area,
103
// so only escape quotes
104
if ch != '"' {
@@ -106,7 +106,10 @@ func (l *lexer) next() bool {
106
}
107
escaped = false
108
} else {
109
- if ch == '"' {
109
+ if quoted && ch == '"' {
110
+ return makeToken()
111
+ }
112
+ if btQuoted && ch == '`' {
113
return makeToken()
114
}
115
}
@@ -151,6 +154,10 @@ func (l *lexer) next() bool {
154
quoted = true
155
continue
156
}
157
+ if ch == '`' {
158
+ btQuoted = true
159
+ continue
160
+ }
161
}
162
163
if escaped {
caddyconfig/caddyfile/lexer_test.go
+32
@@ -199,6 +199,38 @@ func TestLexer(t *testing.T) {
199
{Line: 1, Text: ":8080"},
200
},
201
},
202
+ {
203
+ input: "simple `backtick quoted` string",
204
+ expected: []Token{
205
+ {Line: 1, Text: `simple`},
206
+ {Line: 1, Text: `backtick quoted`},
207
+ {Line: 1, Text: `string`},
208
+ },
209
+ },
210
+ {
211
+ input: "multiline `backtick\nquoted\n` string",
212
+ expected: []Token{
213
+ {Line: 1, Text: `multiline`},
214
+ {Line: 1, Text: "backtick\nquoted\n"},
215
+ {Line: 3, Text: `string`},
216
+ },
217
+ },
218
+ {
219
+ input: "nested `\"quotes inside\" backticks` string",
220
+ expected: []Token{
221
+ {Line: 1, Text: `nested`},
222
+ {Line: 1, Text: `"quotes inside" backticks`},
223
+ {Line: 1, Text: `string`},
224
+ },
225
+ },
226
+ {
227
+ input: "reverse-nested \"`backticks` inside\" quotes",
228
+ expected: []Token{
229
+ {Line: 1, Text: `reverse-nested`},
230
+ {Line: 1, Text: "`backticks` inside"},
231
+ {Line: 1, Text: `quotes`},
232
+ },
233
+ },
234
}
235
236
for i, testCase := range testCases {