Browse Source
			
			
			httpcaddyfile: Improve error on matcher declared outside site block (#3431)
			
			
				master
			
			
		 
		
			
				
					
						 Francis Lavoie
					
					6 years ago
						Francis Lavoie
					
					6 years ago
					
						
							committed by
							
								 GitHub
								GitHub
							
						 
					
				 
				
			 
		 
		
			
				
					
					No known key found for this signature in database
					
						
							GPG Key ID: 4AEE18F83AFDEB23
						
					
				
			
		
		
		
	
		
			
				 2 changed files with 
12 additions and 
0 deletions
			 
			
		 
		
			
				- 
					
					
					 
					caddyconfig/httpcaddyfile/httptype.go
				
- 
					
					
					 
					caddyconfig/httpcaddyfile/httptype_test.go
				
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -54,6 +54,9 @@ func (st ServerType) Setup(inputServerBlocks []caddyfile.ServerBlock, | 
			
		
	
		
			
				
					|  |  |  | 	originalServerBlocks := make([]serverBlock, 0, len(inputServerBlocks)) | 
			
		
	
		
			
				
					|  |  |  | 	for i, sblock := range inputServerBlocks { | 
			
		
	
		
			
				
					|  |  |  | 		for j, k := range sblock.Keys { | 
			
		
	
		
			
				
					|  |  |  | 			if j == 0 && strings.HasPrefix(k, "@") { | 
			
		
	
		
			
				
					|  |  |  | 				return nil, warnings, fmt.Errorf("cannot define a matcher outside of a site block: '%s'", k) | 
			
		
	
		
			
				
					|  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  | 			if _, ok := sbKeys[k]; ok { | 
			
		
	
		
			
				
					|  |  |  | 				return nil, warnings, fmt.Errorf("duplicate site address not allowed: '%s' in %v (site block %d, key %d)", k, sblock.Keys, i, j) | 
			
		
	
		
			
				
					|  |  |  | 			} | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -57,6 +57,15 @@ func TestMatcherSyntax(t *testing.T) { | 
			
		
	
		
			
				
					|  |  |  | 			expectWarn:  false, | 
			
		
	
		
			
				
					|  |  |  | 			expectError: false, | 
			
		
	
		
			
				
					|  |  |  | 		}, | 
			
		
	
		
			
				
					|  |  |  | 		{ | 
			
		
	
		
			
				
					|  |  |  | 			input: `@matcher { | 
			
		
	
		
			
				
					|  |  |  | 				path /matcher-not-allowed/outside-of-site-block/* | 
			
		
	
		
			
				
					|  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  | 			http://localhost
 | 
			
		
	
		
			
				
					|  |  |  | 			`, | 
			
		
	
		
			
				
					|  |  |  | 			expectWarn:  false, | 
			
		
	
		
			
				
					|  |  |  | 			expectError: true, | 
			
		
	
		
			
				
					|  |  |  | 		}, | 
			
		
	
		
			
				
					|  |  |  | 	} { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		adapter := caddyfile.Adapter{ | 
			
		
	
	
		
			
				
					|  |  | 
 |