Repository: syncthing/syncthing (language: go)

Issue:
Tildes break directory autocomplete
### What happened?

When you go to create a new folder and use `~` as a shortcut for your home directory, autocomplete stops working.

Here's what it looks like with `~` (there is no autocomplete):
![Image](https://github.com/user-attachments/assets/557ab5bf-7948-44c0-a991-d047826b593d)

And with `/home/marcus` (real path of my home directory):

![Image](https://github.com/user-attachments/assets/da06aed5-b76d-49f4-a686-b2b7422cdb98)

This behavior (paired with the log output) is strange, as calling the REST API directly through curl with tildes behaves correctly and lists everything in my home directory.

### Syncthing version

v1.29.3

### Platform & operating system

(Arch, with all optional repositories enabled) Linux (64-bit AMD)

### Browser version

LibreWolf 136.0.1

### Relevant log output

```shell
2025-03-14 10:24:45 http: GET "/rest/system/browse?current=%2Fhome%2Fmarcus%2F": status 200, 1473 bytes in 0.94 ms
2025-03-14 10:26:21 http: GET "/rest/svc/random/string?length=10": status 200, 29 bytes in 0.13 ms
2025-03-14 10:26:21 http: GET "/rest/config/defaults/folder": status 200, 1361 bytes in 0.16 ms
2025-03-14 10:26:23 http: GET "/rest/system/browse?current=~": status 200, 21 bytes in 0.21 ms
2025-03-14 10:26:24 http: GET "/rest/system/browse?current=~%2F": status 200, 1473 bytes in 1.10 ms
```


Discussion / hints:

Fix patch:
diff --git a/lib/api/api.go b/lib/api/api.go
index b5be612e1fb..8d07546b9f1 100644
--- a/lib/api/api.go
+++ b/lib/api/api.go
@@ -1764,7 +1764,7 @@ func browse(fsType fs.FilesystemType, current string) []string {
 		return browseRoots(fsType)
 	}
 
-	parent, base := parentAndBase(current)
+	parent, base := filepath.Split(current)
 	ffs := fs.NewFilesystem(fsType, parent)
 	files := browseFiles(ffs, base)
 	for i := range files {
@@ -1800,27 +1800,6 @@ func browseRoots(fsType fs.FilesystemType) []string {
 	return nil
 }
 
-// parentAndBase returns the parent directory and the remaining base of the
-// path. The base may be empty if the path ends with a path separator.
-func parentAndBase(current string) (string, string) {
-	search, _ := fs.ExpandTilde(current)
-	pathSeparator := string(fs.PathSeparator)
-
-	if strings.HasSuffix(current, pathSeparator) && !strings.HasSuffix(search, pathSeparator) {
-		search = search + pathSeparator
-	}
-	searchDir := filepath.Dir(search)
-
-	// The searchFile should be the last component of search, or empty if it
-	// ends with a path separator
-	var searchFile string
-	if !strings.HasSuffix(search, pathSeparator) {
-		searchFile = filepath.Base(search)
-	}
-
-	return searchDir, searchFile
-}
-
 func browseFiles(ffs fs.Filesystem, search string) []string {
 	subdirectories, _ := ffs.DirNames(".")
 	pathSeparator := string(fs.PathSeparator)


Test patch: