From 30b7f9372e443dae6e9495bf3b5391ef3376ae34 Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Tue, 27 Feb 2018 12:37:08 -0800 Subject: [PATCH 1/6] Add integration with URIParser --- REQUIRE | 1 + src/FilePaths.jl | 2 ++ src/uri.jl | 20 ++++++++++++++++++++ test/runtests.jl | 1 + test/test_uri.jl | 6 ++++++ 5 files changed, 30 insertions(+) create mode 100644 src/uri.jl create mode 100644 test/test_uri.jl diff --git a/REQUIRE b/REQUIRE index f725f9d..6072e6d 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1,3 @@ julia 0.6 Compat 0.17.0 +URIParser diff --git a/src/FilePaths.jl b/src/FilePaths.jl index 54e0deb..2354d20 100644 --- a/src/FilePaths.jl +++ b/src/FilePaths.jl @@ -3,6 +3,7 @@ __precompile__() module FilePaths using Compat +import URIParser import Base: == export @@ -80,6 +81,7 @@ include("status.jl") include("posix.jl") include("windows.jl") include("path.jl") +include("uri.jl") include("deprecates.jl") end # end of module diff --git a/src/uri.jl b/src/uri.jl new file mode 100644 index 0000000..df266d6 --- /dev/null +++ b/src/uri.jl @@ -0,0 +1,20 @@ +function URIParser.URI(p::AbstractPath) + if isempty(root(p)) + error("$p is not an absolute path") + end + + b = IOBuffer() + print(b, "file://") + + if !isempty(drive(p)) + print(b, "/") + print(b, drive(p)) + end + + for i=2:length(p.parts) + print(b, "/") + print(b, p.parts[i]) + end + + return URIParser.URI(String(take!(b))) +end diff --git a/test/runtests.jl b/test/runtests.jl index 0f41b97..e50affd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,5 +5,6 @@ using Base.Test include("mode.jl") include("path.jl") +include("test_uri.jl") end diff --git a/test/test_uri.jl b/test/test_uri.jl new file mode 100644 index 0000000..c85aeb4 --- /dev/null +++ b/test/test_uri.jl @@ -0,0 +1,6 @@ +using URIParser +using FilePaths + +@testset "URI" begin + @test string(URI(p"/foo/bar")) == "file:///foo/bar" +end From 1fc20e75be239ae0eeac82da8a0917a5fe37b757 Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Mon, 7 May 2018 11:32:12 -0700 Subject: [PATCH 2/6] Escape during URI conversion --- src/uri.jl | 2 +- test/test_uri.jl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/uri.jl b/src/uri.jl index df266d6..798f415 100644 --- a/src/uri.jl +++ b/src/uri.jl @@ -13,7 +13,7 @@ function URIParser.URI(p::AbstractPath) for i=2:length(p.parts) print(b, "/") - print(b, p.parts[i]) + print(b, URIParser.escape(p.parts[i])) end return URIParser.URI(String(take!(b))) diff --git a/test/test_uri.jl b/test/test_uri.jl index c85aeb4..1fd44f7 100644 --- a/test/test_uri.jl +++ b/test/test_uri.jl @@ -3,4 +3,5 @@ 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 From 42e895f3ebf5cd9cee863343b20f675585c20573 Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Tue, 8 May 2018 21:14:22 -0700 Subject: [PATCH 3/6] Properly import URIParser --- src/FilePaths.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FilePaths.jl b/src/FilePaths.jl index 700bb1f..3cb771e 100644 --- a/src/FilePaths.jl +++ b/src/FilePaths.jl @@ -2,7 +2,7 @@ __precompile__() module FilePaths -using Reexport +using Reexport, URIParser @reexport using FilePathsBase include("uri.jl") From aaaa843c1454ec89d7a6b3741156ef8242eaa8f0 Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Wed, 9 May 2018 11:23:38 -0700 Subject: [PATCH 4/6] Format white spaces away --- src/uri.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/uri.jl b/src/uri.jl index 798f415..a8efa4a 100644 --- a/src/uri.jl +++ b/src/uri.jl @@ -8,13 +8,13 @@ function URIParser.URI(p::AbstractPath) if !isempty(drive(p)) print(b, "/") - print(b, drive(p)) + 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 From e679a495c111533ddff68a6328c04e65078e0375 Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Wed, 9 May 2018 11:59:24 -0700 Subject: [PATCH 5/6] Throw proper exception type --- src/uri.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uri.jl b/src/uri.jl index a8efa4a..8b1fc23 100644 --- a/src/uri.jl +++ b/src/uri.jl @@ -1,6 +1,6 @@ function URIParser.URI(p::AbstractPath) if isempty(root(p)) - error("$p is not an absolute path") + throw(ArgumentError("$p is not an absolute path")) end b = IOBuffer() From 2dbb65562db757fe211156d6c888a90784ffc35d Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Wed, 9 May 2018 11:59:33 -0700 Subject: [PATCH 6/6] Add two URI tests --- test/test_uri.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_uri.jl b/test/test_uri.jl index 1fd44f7..93eb733 100644 --- a/test/test_uri.jl +++ b/test/test_uri.jl @@ -4,4 +4,6 @@ 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" + @test_throws ArgumentError URI(p"foo/bar") + @test string(URI(WindowsPath("C:\\foo\\bar"))) == "file:///C:/foo/bar" end