mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-31 06:21:11 +00:00 
			
		
		
		
	fix: do better parsing of file modes (#9161)
- No longer hardcode the file modes we expect, parse them as numbers and do bitmask tricks that Git does so we allow a more variety of _weird_ file modes that can happen in the wild. - Ref: https://codeberg.org/forgejo/forgejo/pulls/8900#issuecomment-6429175 - Resolves Codeberg/Community#2111 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9161 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
		
					parent
					
						
							
								cee204b5a5
							
						
					
				
			
			
				commit
				
					
						b8906423df
					
				
			
		
					 2 changed files with 69 additions and 31 deletions
				
			
		|  | @ -101,3 +101,38 @@ func TestParseTreeEntriesInvalid(t *testing.T) { | |||
| 	require.Error(t, err) | ||||
| 	assert.Empty(t, entries) | ||||
| } | ||||
| 
 | ||||
| func TestParseMode(t *testing.T) { | ||||
| 	ok := func(t *testing.T, mode string, entry EntryMode) { | ||||
| 		t.Helper() | ||||
| 		actualEntry, err := parseMode(mode) | ||||
| 		require.NoError(t, err) | ||||
| 		assert.Equal(t, entry, actualEntry) | ||||
| 	} | ||||
| 
 | ||||
| 	fail := func(t *testing.T, mode string) { | ||||
| 		t.Helper() | ||||
| 		entry, err := parseMode(mode) | ||||
| 		require.Error(t, err) | ||||
| 		assert.Zero(t, entry) | ||||
| 	} | ||||
| 
 | ||||
| 	ok(t, "100644", EntryModeBlob) | ||||
| 	ok(t, "100755", EntryModeExec) | ||||
| 	ok(t, "100754", EntryModeExec) | ||||
| 	ok(t, "100700", EntryModeExec) | ||||
| 	ok(t, "100744", EntryModeExec) | ||||
| 	ok(t, "120000", EntryModeSymlink) | ||||
| 	ok(t, "120644", EntryModeSymlink) | ||||
| 	ok(t, "160000", EntryModeCommit) | ||||
| 	ok(t, "160644", EntryModeCommit) | ||||
| 	ok(t, "040000", EntryModeTree) | ||||
| 	ok(t, "040755", EntryModeTree) | ||||
| 	ok(t, "040775", EntryModeTree) | ||||
| 	ok(t, "040754", EntryModeTree) | ||||
| 
 | ||||
| 	fail(t, "not-a-number") | ||||
| 	fail(t, "000000") | ||||
| 	fail(t, "400000") | ||||
| 	fail(t, "111111") | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue