Skip to content

Commit

Permalink
Merge pull request #57 from jmkuhn/uri
Browse files Browse the repository at this point in the history
Deprecate URIParser; use URIs
  • Loading branch information
rofinn authored Apr 23, 2021
2 parents 2ad4e04 + aa8e582 commit 76df5f7
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ MacroTools = "0.5"
Reexport = "0.2, 1.0"
Requires = "1"
URIParser = "0.4"
URIs = "1.1"
julia = "1"

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

[targets]
test = ["Glob", "Test", "URIParser"]
test = ["Glob", "Test", "URIParser", "URIs"]
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ julia> glob("*test*.jl", p"test")

URIParsing:
```julia
julia> using URIs

julia> URI(cwd() / p"test/runtests.jl")
URI(file:///Users/rory/repos/FilePaths.jl/test/runtests.jl)
URI("file:///Users/rory/repos/FilePaths.jl/test/runtests.jl")
```

Writing `String` and `AbstractPath` compatible code:
Expand Down
3 changes: 2 additions & 1 deletion src/FilePaths.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ include("compat.jl")

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

end # end of module
1 change: 1 addition & 0 deletions src/uri.jl → src/uriparser.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using .URIParser

function URIParser.URI(p::AbstractPath; query="", fragment="")
Base.depwarn("`URIParser` is deprecated, use `URIs` instead.", :URIParser)
if isempty(p.root)
throw(ArgumentError("$p is not an absolute path"))
end
Expand Down
24 changes: 24 additions & 0 deletions src/uris.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using .URIs

const absent = SubString("absent", 1, 0)

function URIs.URI(p::AbstractPath; query=absent, fragment=absent)
if isempty(p.root)
throw(ArgumentError("$p is not an absolute path"))
end

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

if !isempty(p.drive)
print(b, "/")
print(b, p.drive)
end

for s in p.segments
print(b, "/")
print(b, URIs.escapeuri(s))
end

return URIs.URI(URIs.URI(String(take!(b))); query=query, fragment=fragment)
end
21 changes: 15 additions & 6 deletions test/test_uri.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
using URIParser
using URIs
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"
@test string(URI(p"/foo/bar", query="querypart", fragment="fragmentpart")) == "file:///foo/bar?querypart#fragmentpart"
@testset "URIParser" begin
@test string(URIParser.URI(p"/foo/bar")) == "file:///foo/bar"
@test string(URIParser.URI(p"/foo foo/bar")) == "file:///foo%20foo/bar"
@test_throws ArgumentError URIParser.URI(p"foo/bar")
@test string(URIParser.URI(WindowsPath("C:\\foo\\bar"))) == "file:///C:/foo/bar"
@test string(URIParser.URI(p"/foo/bar", query="querypart", fragment="fragmentpart")) == "file:///foo/bar?querypart#fragmentpart"
end

@testset "URIs" begin
@test string(URIs.URI(p"/foo/bar")) == "file:///foo/bar"
@test string(URIs.URI(p"/foo foo/bar")) == "file:///foo%20foo/bar"
@test_throws ArgumentError URIs.URI(p"foo/bar")
@test string(URIs.URI(WindowsPath("C:\\foo\\bar"))) == "file:///C:/foo/bar"
@test string(URIs.URI(p"/foo/bar", query="querypart", fragment="fragmentpart")) == "file:///foo/bar?querypart#fragmentpart"
end

0 comments on commit 76df5f7

Please # to comment.