Skip to content
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

Add integration with URIParser #22

Merged
merged 8 commits into from
May 10, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
julia 0.6
Compat 0.17.0
URIParser
FilePathsBase 0.1.0
Reexport 0.1.0
Reexport 0.1.0
4 changes: 3 additions & 1 deletion src/FilePaths.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ __precompile__()

module FilePaths

using Reexport
using Reexport, URIParser
@reexport using FilePathsBase

include("uri.jl")

end # end of module
20 changes: 20 additions & 0 deletions src/uri.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function URIParser.URI(p::AbstractPath)
if isempty(root(p))
error("$p is not an absolute path")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to throw an ArgumentError here and we should test that error condition.

end

b = IOBuffer()
print(b, "file://")

if !isempty(drive(p))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably test the drive behaviour.

print(b, "/")
print(b, drive(p))
end

for i=2:length(p.parts)
print(b, "/")
print(b, URIParser.escape(p.parts[i]))
end

return URIParser.URI(String(take!(b)))
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ using Base.Test

@testset "FilePaths" begin

include("test_uri.jl")

end
7 changes: 7 additions & 0 deletions test/test_uri.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using URIParser
using FilePaths

@testset "URI" begin
@test string(URI(p"/foo/bar")) == "file:///foo/bar"
@test string(URI(p"/foo foo/bar")) == "file:///foo%20foo/bar"
end