mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Check for either escaped or unescaped wiki filenames (#8408)
* Check for either escaped or unescaped wiki filenames + Gitea currently saves wiki pages with escaped filenames. + Wikis mirrored from other places like Github use unescaped filenames. + We need to be checking for filenames in either format to increase compatibility. * Better logic for escaped and unescaped wiki filenames Co-Authored-By: null <guillep2k@users.noreply.github.com>
This commit is contained in:
		@@ -8,6 +8,7 @@ package repo
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"io/ioutil"
 | 
						"io/ioutil"
 | 
				
			||||||
 | 
						"net/url"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -68,11 +69,22 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error)
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						// The longest name should be checked first
 | 
				
			||||||
	for _, entry := range entries {
 | 
						for _, entry := range entries {
 | 
				
			||||||
		if entry.IsRegular() && entry.Name() == target {
 | 
							if entry.IsRegular() && entry.Name() == target {
 | 
				
			||||||
			return entry, nil
 | 
								return entry, nil
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						// Then the unescaped, shortest alternative
 | 
				
			||||||
 | 
						var unescapedTarget string
 | 
				
			||||||
 | 
						if unescapedTarget, err = url.QueryUnescape(target); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for _, entry := range entries {
 | 
				
			||||||
 | 
							if entry.IsRegular() && entry.Name() == unescapedTarget {
 | 
				
			||||||
 | 
								return entry, nil
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return nil, nil
 | 
						return nil, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user