Skip to content

Commit 76df5f7

Browse files
authored
Merge pull request #57 from jmkuhn/uri
Deprecate URIParser; use URIs
2 parents 2ad4e04 + aa8e582 commit 76df5f7

File tree

6 files changed

+48
-9
lines changed

6 files changed

+48
-9
lines changed

Project.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ MacroTools = "0.5"
1616
Reexport = "0.2, 1.0"
1717
Requires = "1"
1818
URIParser = "0.4"
19+
URIs = "1.1"
1920
julia = "1"
2021

2122
[extras]
2223
Glob = "c27321d9-0574-5035-807b-f59d2c89b15c"
2324
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2425
URIParser = "30578b45-9adc-5946-b283-645ec420af67"
26+
URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
2527

2628
[targets]
27-
test = ["Glob", "Test", "URIParser"]
29+
test = ["Glob", "Test", "URIParser", "URIs"]

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ julia> glob("*test*.jl", p"test")
3131

3232
URIParsing:
3333
```julia
34+
julia> using URIs
35+
3436
julia> URI(cwd() / p"test/runtests.jl")
35-
URI(file:///Users/rory/repos/FilePaths.jl/test/runtests.jl)
37+
URI("file:///Users/rory/repos/FilePaths.jl/test/runtests.jl")
3638
```
3739

3840
Writing `String` and `AbstractPath` compatible code:

src/FilePaths.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ include("compat.jl")
1010

1111
function __init__()
1212
@require Glob="c27321d9-0574-5035-807b-f59d2c89b15c" include("glob.jl")
13-
@require URIParser="30578b45-9adc-5946-b283-645ec420af67" include("uri.jl")
13+
@require URIParser="30578b45-9adc-5946-b283-645ec420af67" include("uriparser.jl")
14+
@require URIs="5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4" include("uris.jl")
1415
end
1516

1617
end # end of module

src/uri.jl src/uriparser.jl

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using .URIParser
22

33
function URIParser.URI(p::AbstractPath; query="", fragment="")
4+
Base.depwarn("`URIParser` is deprecated, use `URIs` instead.", :URIParser)
45
if isempty(p.root)
56
throw(ArgumentError("$p is not an absolute path"))
67
end

src/uris.jl

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using .URIs
2+
3+
const absent = SubString("absent", 1, 0)
4+
5+
function URIs.URI(p::AbstractPath; query=absent, fragment=absent)
6+
if isempty(p.root)
7+
throw(ArgumentError("$p is not an absolute path"))
8+
end
9+
10+
b = IOBuffer()
11+
print(b, "file://")
12+
13+
if !isempty(p.drive)
14+
print(b, "/")
15+
print(b, p.drive)
16+
end
17+
18+
for s in p.segments
19+
print(b, "/")
20+
print(b, URIs.escapeuri(s))
21+
end
22+
23+
return URIs.URI(URIs.URI(String(take!(b))); query=query, fragment=fragment)
24+
end

test/test_uri.jl

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
using URIParser
2+
using URIs
23
using FilePaths
34

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-
@test string(URI(p"/foo/bar", query="querypart", fragment="fragmentpart")) == "file:///foo/bar?querypart#fragmentpart"
5+
@testset "URIParser" begin
6+
@test string(URIParser.URI(p"/foo/bar")) == "file:///foo/bar"
7+
@test string(URIParser.URI(p"/foo foo/bar")) == "file:///foo%20foo/bar"
8+
@test_throws ArgumentError URIParser.URI(p"foo/bar")
9+
@test string(URIParser.URI(WindowsPath("C:\\foo\\bar"))) == "file:///C:/foo/bar"
10+
@test string(URIParser.URI(p"/foo/bar", query="querypart", fragment="fragmentpart")) == "file:///foo/bar?querypart#fragmentpart"
11+
end
12+
13+
@testset "URIs" begin
14+
@test string(URIs.URI(p"/foo/bar")) == "file:///foo/bar"
15+
@test string(URIs.URI(p"/foo foo/bar")) == "file:///foo%20foo/bar"
16+
@test_throws ArgumentError URIs.URI(p"foo/bar")
17+
@test string(URIs.URI(WindowsPath("C:\\foo\\bar"))) == "file:///C:/foo/bar"
18+
@test string(URIs.URI(p"/foo/bar", query="querypart", fragment="fragmentpart")) == "file:///foo/bar?querypart#fragmentpart"
1019
end

0 commit comments

Comments
 (0)