Skip to content

Commit

Permalink
path/filepath: add Localize
Browse files Browse the repository at this point in the history
Implemented filepath.Localize using internal/safefilepath.FromFS.

Fixes golang#57151

Change-Id: I98c6a211d77fa5c8733306b5ef39950bae07fb5c
  • Loading branch information
qiulaidongfeng committed Aug 17, 2023
1 parent 1c00354 commit 766cdf2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/next/57151.txt
@@ -0,0 +1 @@
pkg path/filepath, func Localize(string) (string, error) #57151
10 changes: 10 additions & 0 deletions src/path/filepath/path.go
Expand Up @@ -13,6 +13,7 @@ package filepath

import (
"errors"
"internal/safefilepath"
"io/fs"
"os"
"runtime"
Expand Down Expand Up @@ -681,3 +682,12 @@ func Dir(path string) string {
func VolumeName(path string) string {
return FromSlash(path[:volumeNameLen(path)])
}

// Localize converts a slash-separated path into an operating-system path.
//
// Localize returns an error if the path cannot be represented by the operating
// system. For example, paths containing '\' and ':' characters are rejected
// on Windows.
func Localize(path string) (string, error) {
return safefilepath.FromFS(path)
}

0 comments on commit 766cdf2

Please sign in to comment.