mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-31 06:21:11 +00:00 
			
		
		
		
	chore: add extra shell escape tests
This commit is contained in:
		
					parent
					
						
							
								900ea0ce5a
							
						
					
				
			
			
				commit
				
					
						1c66c4e11a
					
				
			
		
					 1 changed files with 18 additions and 4 deletions
				
			
		|  | @ -3,7 +3,11 @@ | ||||||
| 
 | 
 | ||||||
| package util | package util | ||||||
| 
 | 
 | ||||||
| import "testing" | import ( | ||||||
|  | 	"testing" | ||||||
|  | 
 | ||||||
|  | 	"github.com/stretchr/testify/assert" | ||||||
|  | ) | ||||||
| 
 | 
 | ||||||
| func TestShellEscape(t *testing.T) { | func TestShellEscape(t *testing.T) { | ||||||
| 	tests := []struct { | 	tests := []struct { | ||||||
|  | @ -79,13 +83,23 @@ func TestShellEscape(t *testing.T) { | ||||||
| 			"Single quotes don't need to escape except for '...", | 			"Single quotes don't need to escape except for '...", | ||||||
| 			"~/<gitea> ${gitea} `gitea` (gitea) !gitea! \"gitea\" \\gitea\\ 'gitea'", | 			"~/<gitea> ${gitea} `gitea` (gitea) !gitea! \"gitea\" \\gitea\\ 'gitea'", | ||||||
| 			"~/'<gitea> ${gitea} `gitea` (gitea) !gitea! \"gitea\" \\gitea\\ '\\''gitea'\\'", | 			"~/'<gitea> ${gitea} `gitea` (gitea) !gitea! \"gitea\" \\gitea\\ '\\''gitea'\\'", | ||||||
|  | 		}, { | ||||||
|  | 			"Inline command", | ||||||
|  | 			"some`echo foo`thing", | ||||||
|  | 			"\"some\\`echo foo\\`thing\"", | ||||||
|  | 		}, { | ||||||
|  | 			"Substitution", | ||||||
|  | 			`;${HOME}`, | ||||||
|  | 			`";\${HOME}"`, | ||||||
|  | 		}, { | ||||||
|  | 			"ANSI Escape codes (not escaped)", | ||||||
|  | 			"\033[31;1;4mHello\033[0m", | ||||||
|  | 			"\"\x1b[31;1;4mHello\x1b[0m\"", | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	for _, tt := range tests { | 	for _, tt := range tests { | ||||||
| 		t.Run(tt.name, func(t *testing.T) { | 		t.Run(tt.name, func(t *testing.T) { | ||||||
| 			if got := ShellEscape(tt.toEscape); got != tt.want { | 			assert.Equal(t, tt.want, ShellEscape(tt.toEscape)) | ||||||
| 				t.Errorf("ShellEscape(%q):\nGot:    %s\nWanted: %s", tt.toEscape, got, tt.want) |  | ||||||
| 			} |  | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue