Skip to content

Commit 026f762

Browse files
authored
Merge pull request #22 from davidanthoff/uri
Add integration with URIParser
2 parents b78f504 + 2dbb655 commit 026f762

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

REQUIRE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
julia 0.6
22
Compat 0.17.0
3+
URIParser
34
FilePathsBase 0.1.0
4-
Reexport 0.1.0
5+
Reexport 0.1.0

src/FilePaths.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ __precompile__()
22

33
module FilePaths
44

5-
using Reexport
5+
using Reexport, URIParser
66
@reexport using FilePathsBase
77

8+
include("uri.jl")
9+
810
end # end of module

src/uri.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function URIParser.URI(p::AbstractPath)
2+
if isempty(root(p))
3+
throw(ArgumentError("$p is not an absolute path"))
4+
end
5+
6+
b = IOBuffer()
7+
print(b, "file://")
8+
9+
if !isempty(drive(p))
10+
print(b, "/")
11+
print(b, drive(p))
12+
end
13+
14+
for i=2:length(p.parts)
15+
print(b, "/")
16+
print(b, URIParser.escape(p.parts[i]))
17+
end
18+
19+
return URIParser.URI(String(take!(b)))
20+
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ using Base.Test
33

44
@testset "FilePaths" begin
55

6+
include("test_uri.jl")
67

78
end

test/test_uri.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using URIParser
2+
using FilePaths
3+
4+
@testset "URI" begin
5+
@test string(URI(p"/foo/bar")) == "file:///foo/bar"
6+
@test string(URI(p"/foo foo/bar")) == "file:///foo%20foo/bar"
7+
@test_throws ArgumentError URI(p"foo/bar")
8+
@test string(URI(WindowsPath("C:\\foo\\bar"))) == "file:///C:/foo/bar"
9+
end

0 commit comments

Comments
 (0)