Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 12, 18:15 UTC
caddyfile: Allow heredoc blank lines (#6051)
Aziz Rmadi committed
Jan 18, 2024 at 21:57 UTC
d9aded016cc2e1ba5d70bf953030be70d2c15681
2 files changed
+47
caddyconfig/caddyfile/lexer.go
+5
@@ -313,6 +313,11 @@ func (l *lexer) finalizeHeredoc(val []rune, marker string) ([]rune, error) {
313
// iterate over each line and strip the whitespace from the front
314
var out string
315
for lineNum, lineText := range lines[:len(lines)-1] {
316
+ if lineText == "" {
317
+ out += "\n"
318
+ continue
319
+ }
320
+
321
// find an exact match for the padding
322
index := strings.Index(lineText, paddingToStrip)
323
caddyconfig/caddyfile/lexer_test.go
+42
@@ -445,6 +445,48 @@ EOF same-line-arg
445
expectErr: true,
446
errorMessage: "mismatched leading whitespace in heredoc <<EOF on line #2 [ content], expected whitespace [\t\t] to match the closing marker",
447
},
448
+ {
449
+ input: []byte(`heredoc <<EOF
450
+The next line is a blank line
451
+
452
+The previous line is a blank line
453
+EOF`),
454
+ expected: []Token{
455
+ {Line: 1, Text: "heredoc"},
456
+ {Line: 1, Text: "The next line is a blank line\n\nThe previous line is a blank line"},
457
+ },
458
+ },
459
+ {
460
+ input: []byte(`heredoc <<EOF
461
+ One tab indented heredoc with blank next line
462
+
463
+ One tab indented heredoc with blank previous line
464
+ EOF`),
465
+ expected: []Token{
466
+ {Line: 1, Text: "heredoc"},
467
+ {Line: 1, Text: "One tab indented heredoc with blank next line\n\nOne tab indented heredoc with blank previous line"},
468
+ },
469
+ },
470
+ {
471
+ input: []byte(`heredoc <<EOF
472
+The next line is a blank line with one tab
473
+
474
+The previous line is a blank line with one tab
475
+EOF`),
476
+ expected: []Token{
477
+ {Line: 1, Text: "heredoc"},
478
+ {Line: 1, Text: "The next line is a blank line with one tab\n\t\nThe previous line is a blank line with one tab"},
479
+ },
480
+ },
481
+ {
482
+ input: []byte(`heredoc <<EOF
483
+ The next line is a blank line with one tab less than the correct indentation
484
+
485
+ The previous line is a blank line with one tab less than the correct indentation
486
+ EOF`),
487
+ expectErr: true,
488
+ errorMessage: "mismatched leading whitespace in heredoc <<EOF on line #3 [\t], expected whitespace [\t\t] to match the closing marker",
489
+ },
490
}
491
492
for i, testCase := range testCases {