Skip to content

URL: Don't standardize relative file paths #792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2024

Conversation

jrflat
Copy link
Contributor

@jrflat jrflat commented Jul 26, 2024

Resolves #790 (thanks @nicklockwood for filing!)

We should not standardize the relative path outside of the context of its base URL, such as when calculating the absolute .path(). This allows us to properly handle ".." segments at the beginning of the relative path, such as in

let baseURL = URL(filePath: "/docs/src/")
let result = URL(filePath: "../images/foo.png", relativeTo: baseURL)
XCTAssertEqual(result.path(), "/docs/images/foo.png")

Note that if the inputted path is absolute, e.g. "/../images/foo.png", we should not resolve against the base URL. I've added a small unit test to cover both cases.

@jrflat jrflat changed the title (132587065) URL: Don't standardize relative file paths URL: Don't standardize relative file paths Jul 26, 2024
@jrflat
Copy link
Contributor Author

jrflat commented Jul 26, 2024

@swift-ci please test

@parkera parkera merged commit e1223a0 into swiftlang:main Jul 27, 2024
3 checks passed
parkera pushed a commit to parkera/swift-foundation that referenced this pull request Jul 27, 2024
@DmT021
Copy link

DmT021 commented Jul 27, 2024

@jrflat @parkera Could it be the source of this error:

/home/build-user/swift-integration-tests/test-static-stdlib/test-static-stdlib.test:7:8: error: CHECK: expected string not found in input
CHECK: foo bar baz: file:/foo
       ^
<stdin>:1:1: note: scanning from here
foo bar baz: file:///foo
^

Input file: <stdin>
Check file: /home/build-user/swift-integration-tests/test-static-stdlib/test-static-stdlib.test

-dump-input=help explains the following input dump.

Input was:
<<<<<<
         1: foo bar baz: file:///foo 
check:7     X~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
>>>>>>

error: command failed with exit status: 1

I see it on CI in this build: https://ci.swift.org/job/swift-PR-Linux/16654/console

parkera added a commit that referenced this pull request Jul 28, 2024
(cherry picked from commit e1223a0)

Co-authored-by: Jonathan Flat <50605158+jrflat@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

URL(fileURLWithPath:relativeTo:) regression on Linux
3 participants