1
Fork 0

Fix absolute issues

This commit is contained in:
Chris Denton 2021-12-09 14:31:22 +00:00
parent d59d32c4f1
commit 81cc3afe20
No known key found for this signature in database
GPG key ID: 713472F2F45627DE
4 changed files with 5 additions and 4 deletions

View file

@ -3199,7 +3199,7 @@ impl Error for StripPrefixError {
/// # fn main() {} /// # fn main() {}
/// ``` /// ```
/// ///
/// The paths is resolved using [POSIX semantics][posix-semantics] except that /// The path is resolved using [POSIX semantics][posix-semantics] except that
/// it stops short of resolving symlinks. This means it will keep `..` /// it stops short of resolving symlinks. This means it will keep `..`
/// components and trailing slashes. /// components and trailing slashes.
/// ///
@ -3231,7 +3231,7 @@ impl Error for StripPrefixError {
/// ///
/// [posix-semantics]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13 /// [posix-semantics]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13
/// [windows-path]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfullpathnamew /// [windows-path]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfullpathnamew
#[unstable(feature = "absolute_path", issue = "none")] #[unstable(feature = "absolute_path", issue = "92750")]
pub fn absolute<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> { pub fn absolute<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
let path = path.as_ref(); let path = path.as_ref();
if path.as_os_str().is_empty() { if path.as_os_str().is_empty() {

View file

@ -1,4 +1,5 @@
use crate::ffi::OsStr; use crate::ffi::OsStr;
use crate::io;
use crate::path::{Path, PathBuf, Prefix}; use crate::path::{Path, PathBuf, Prefix};
use crate::sys::unsupported; use crate::sys::unsupported;

View file

@ -1,4 +1,5 @@
use crate::ffi::OsStr; use crate::ffi::OsStr;
use crate::io;
use crate::path::{Path, PathBuf, Prefix}; use crate::path::{Path, PathBuf, Prefix};
use crate::sys::unsupported; use crate::sys::unsupported;

View file

@ -1,7 +1,6 @@
use crate::env; use crate::env;
use crate::ffi::OsStr; use crate::ffi::OsStr;
use crate::io; use crate::io;
use crate::os::unix::ffi::OsStrExt;
use crate::path::{Path, PathBuf, Prefix}; use crate::path::{Path, PathBuf, Prefix};
#[inline] #[inline]
@ -30,7 +29,7 @@ pub(crate) fn absolute(path: &Path) -> io::Result<PathBuf> {
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13 // https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13
let mut components = path.components(); let mut components = path.components();
let path_os = path.as_os_str().as_bytes(); let path_os = path.as_os_str().bytes();
let mut normalized = if path.is_absolute() { let mut normalized = if path.is_absolute() {
// "If a pathname begins with two successive <slash> characters, the // "If a pathname begins with two successive <slash> characters, the