mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-31 02:27:19 -04:00 
			
		
		
		
	caddyfile: fix nested quotes formatted incorrectly by fmt (#7045)
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				Tests / test (./cmd/caddy/caddy, ~1.25.0, ubuntu-latest, 0, 1.25, linux) (push) Failing after 49s
				
			
		
			
				
	
				Tests / test (s390x on IBM Z) (push) Has been skipped
				
			
		
			
				
	
				Tests / goreleaser-check (push) Has been skipped
				
			
		
			
				
	
				Cross-Build / build (~1.25.0, 1.25, aix) (push) Failing after 15s
				
			
		
			
				
	
				Cross-Build / build (~1.25.0, 1.25, darwin) (push) Failing after 14s
				
			
		
			
				
	
				Cross-Build / build (~1.25.0, 1.25, dragonfly) (push) Failing after 14s
				
			
		
			
				
	
				Cross-Build / build (~1.25.0, 1.25, freebsd) (push) Failing after 14s
				
			
		
			
				
	
				Cross-Build / build (~1.25.0, 1.25, illumos) (push) Failing after 13s
				
			
		
			
				
	
				Cross-Build / build (~1.25.0, 1.25, linux) (push) Failing after 14s
				
			
		
			
				
	
				Cross-Build / build (~1.25.0, 1.25, netbsd) (push) Failing after 14s
				
			
		
			
				
	
				Cross-Build / build (~1.25.0, 1.25, openbsd) (push) Failing after 15s
				
			
		
			
				
	
				Cross-Build / build (~1.25.0, 1.25, solaris) (push) Failing after 14s
				
			
		
			
				
	
				Cross-Build / build (~1.25.0, 1.25, windows) (push) Failing after 14s
				
			
		
			
				
	
				Lint / lint (ubuntu-latest, linux) (push) Failing after 13s
				
			
		
			
				
	
				Lint / govulncheck (push) Successful in 1m37s
				
			
		
			
				
	
				Lint / dependency-review (push) Failing after 15s
				
			
		
			
				
	
				Tests / test (./cmd/caddy/caddy, ~1.25.0, macos-14, 0, 1.25, mac) (push) Has been cancelled
				
			
		
			
				
	
				Tests / test (./cmd/caddy/caddy.exe, ~1.25.0, windows-latest, True, 1.25, windows) (push) Has been cancelled
				
			
		
			
				
	
				Lint / lint (macos-14, mac) (push) Has been cancelled
				
			
		
			
				
	
				Lint / lint (windows-latest, windows) (push) Has been cancelled
				
			
		
			
				
	
				OpenSSF Scorecard supply-chain security / Scorecard analysis (push) Failing after 2m12s
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	Tests / test (./cmd/caddy/caddy, ~1.25.0, ubuntu-latest, 0, 1.25, linux) (push) Failing after 49s
				
			Tests / test (s390x on IBM Z) (push) Has been skipped
				
			Tests / goreleaser-check (push) Has been skipped
				
			Cross-Build / build (~1.25.0, 1.25, aix) (push) Failing after 15s
				
			Cross-Build / build (~1.25.0, 1.25, darwin) (push) Failing after 14s
				
			Cross-Build / build (~1.25.0, 1.25, dragonfly) (push) Failing after 14s
				
			Cross-Build / build (~1.25.0, 1.25, freebsd) (push) Failing after 14s
				
			Cross-Build / build (~1.25.0, 1.25, illumos) (push) Failing after 13s
				
			Cross-Build / build (~1.25.0, 1.25, linux) (push) Failing after 14s
				
			Cross-Build / build (~1.25.0, 1.25, netbsd) (push) Failing after 14s
				
			Cross-Build / build (~1.25.0, 1.25, openbsd) (push) Failing after 15s
				
			Cross-Build / build (~1.25.0, 1.25, solaris) (push) Failing after 14s
				
			Cross-Build / build (~1.25.0, 1.25, windows) (push) Failing after 14s
				
			Lint / lint (ubuntu-latest, linux) (push) Failing after 13s
				
			Lint / govulncheck (push) Successful in 1m37s
				
			Lint / dependency-review (push) Failing after 15s
				
			Tests / test (./cmd/caddy/caddy, ~1.25.0, macos-14, 0, 1.25, mac) (push) Has been cancelled
				
			Tests / test (./cmd/caddy/caddy.exe, ~1.25.0, windows-latest, True, 1.25, windows) (push) Has been cancelled
				
			Lint / lint (macos-14, mac) (push) Has been cancelled
				
			Lint / lint (windows-latest, windows) (push) Has been cancelled
				
			OpenSSF Scorecard supply-chain security / Scorecard analysis (push) Failing after 2m12s
				
			* Fix incorrectly formatted quote within quotes with fmt * Fix incorrectly formatted quote within quotes with fmt
This commit is contained in:
		
							parent
							
								
									abe0acabb6
								
							
						
					
					
						commit
						92c8bc7322
					
				| @ -53,7 +53,7 @@ func Format(input []byte) []byte { | |||||||
| 		newLines int // count of newlines consumed | 		newLines int // count of newlines consumed | ||||||
| 
 | 
 | ||||||
| 		comment bool   // whether we're in a comment | 		comment bool   // whether we're in a comment | ||||||
| 		quoted  bool // whether we're in a quoted segment | 		quotes  string // encountered quotes ('', '`', '"', '"`', '`"') | ||||||
| 		escaped bool   // whether current char is escaped | 		escaped bool   // whether current char is escaped | ||||||
| 
 | 
 | ||||||
| 		heredoc              heredocState // whether we're in a heredoc | 		heredoc              heredocState // whether we're in a heredoc | ||||||
| @ -62,7 +62,6 @@ func Format(input []byte) []byte { | |||||||
| 		heredocClosingMarker []rune | 		heredocClosingMarker []rune | ||||||
| 
 | 
 | ||||||
| 		nesting int // indentation level | 		nesting int // indentation level | ||||||
| 		withinBackquote bool |  | ||||||
| 	) | 	) | ||||||
| 
 | 
 | ||||||
| 	write := func(ch rune) { | 	write := func(ch rune) { | ||||||
| @ -89,12 +88,8 @@ func Format(input []byte) []byte { | |||||||
| 			} | 			} | ||||||
| 			panic(err) | 			panic(err) | ||||||
| 		} | 		} | ||||||
| 		if ch == '`' { |  | ||||||
| 			withinBackquote = !withinBackquote |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		// detect whether we have the start of a heredoc | 		// detect whether we have the start of a heredoc | ||||||
| 		if !quoted && (heredoc == heredocClosed && !heredocEscaped) && | 		if quotes == "" && (heredoc == heredocClosed && !heredocEscaped) && | ||||||
| 			space && last == '<' && ch == '<' { | 			space && last == '<' && ch == '<' { | ||||||
| 			write(ch) | 			write(ch) | ||||||
| 			heredoc = heredocOpening | 			heredoc = heredocOpening | ||||||
| @ -180,16 +175,38 @@ func Format(input []byte) []byte { | |||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if quoted { | 		if ch == '`' { | ||||||
|  | 			switch quotes { | ||||||
|  | 			case "\"`": | ||||||
|  | 				quotes = "\"" | ||||||
|  | 			case "`": | ||||||
|  | 				quotes = "" | ||||||
|  | 			case "\"": | ||||||
|  | 				quotes = "\"`" | ||||||
|  | 			default: | ||||||
|  | 				quotes = "`" | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		if quotes == "\"" { | ||||||
| 			if ch == '"' { | 			if ch == '"' { | ||||||
| 				quoted = false | 				quotes = "" | ||||||
| 			} | 			} | ||||||
| 			write(ch) | 			write(ch) | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if space && ch == '"' { | 		if ch == '"' { | ||||||
| 			quoted = true | 			switch quotes { | ||||||
|  | 			case "": | ||||||
|  | 				if space { | ||||||
|  | 					quotes = "\"" | ||||||
|  | 				} | ||||||
|  | 			case "`\"": | ||||||
|  | 				quotes = "`" | ||||||
|  | 			case "\"`": | ||||||
|  | 				quotes = "" | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if unicode.IsSpace(ch) { | 		if unicode.IsSpace(ch) { | ||||||
| @ -245,7 +262,7 @@ func Format(input []byte) []byte { | |||||||
| 				write(' ') | 				write(' ') | ||||||
| 			} | 			} | ||||||
| 			openBraceWritten = false | 			openBraceWritten = false | ||||||
| 			if withinBackquote { | 			if quotes == "`" { | ||||||
| 				write('{') | 				write('{') | ||||||
| 				openBraceWritten = true | 				openBraceWritten = true | ||||||
| 				continue | 				continue | ||||||
| @ -253,7 +270,7 @@ func Format(input []byte) []byte { | |||||||
| 			continue | 			continue | ||||||
| 
 | 
 | ||||||
| 		case ch == '}' && (spacePrior || !openBrace): | 		case ch == '}' && (spacePrior || !openBrace): | ||||||
| 			if withinBackquote { | 			if quotes == "`" { | ||||||
| 				write('}') | 				write('}') | ||||||
| 				continue | 				continue | ||||||
| 			} | 			} | ||||||
|  | |||||||
| @ -444,6 +444,11 @@ block2 { | |||||||
| 			input:       "block {respond \"All braces should remain: {{now | date `2006`}}\"}", | 			input:       "block {respond \"All braces should remain: {{now | date `2006`}}\"}", | ||||||
| 			expect:      "block {respond \"All braces should remain: {{now | date `2006`}}\"}", | 			expect:      "block {respond \"All braces should remain: {{now | date `2006`}}\"}", | ||||||
| 		}, | 		}, | ||||||
|  | 		{ | ||||||
|  | 			description: "Preserve quoted backticks and backticked quotes", | ||||||
|  | 			input:       "block { respond \"`\" } block { respond `\"`}", | ||||||
|  | 			expect:      "block {\n\trespond \"`\"\n}\n\nblock {\n\trespond `\"`\n}", | ||||||
|  | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			description: "No trailing space on line before env variable", | 			description: "No trailing space on line before env variable", | ||||||
| 			input: `{ | 			input: `{ | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user