diff --git a/REQUIRE b/REQUIRE index 04702fb..9927ee1 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1,2 @@ julia 0.6 -Compat 0.9.5 +Compat 0.54.0 diff --git a/src/URIParser.jl b/src/URIParser.jl index a8b304d..c753a94 100644 --- a/src/URIParser.jl +++ b/src/URIParser.jl @@ -14,6 +14,12 @@ if VERSION >= v"0.7.0-DEV.2915" using Base.Unicode: isascii end +if VERSION >= v"0.7.0-DEV.3526" + _parse(T, s, b) = Base.parse(Int, s, base=b) +else + _parse(T, s, b) = Base.parse(Int, s, b) +end + include("parser.jl") include("esc.jl") include("utils.jl") diff --git a/src/esc.jl b/src/esc.jl index d8e7a68..43e20b5 100644 --- a/src/esc.jl +++ b/src/esc.jl @@ -1,7 +1,7 @@ const escaped_regex = r"%([0-9a-fA-F]{2})" # Escaping -const control_array = vcat(map(UInt8, 0:parse(Int,"1f",16))) +const control_array = vcat(map(UInt8, 0:_parse(Int, "1f", 16))) const control = String(control_array)*"\x7f" const space = String(" ") const delims = String("%<>\"") @@ -22,14 +22,14 @@ function unescape(str) c = str[i] i += 1 if c == '%' - c = parse(UInt8, str[i:i+1], 16) + c = _parse(UInt8, str[i:i+1], 16) i += 2 end push!(r, c) end return String(r) end -unescape_form(str) = unescape(replace(str, "+", " ")) +unescape_form(str) = unescape(replace(str, "+" => " ")) hex_string(x) = string('%', uppercase(hex(x,2))) @@ -39,7 +39,7 @@ function escape_with(str, use) out = IOBuffer() chars = Set(use) i = start(str) - e = endof(str) + e = lastindex(str) while i <= e i_next = nextind(str, i) if i_next == i + 1 @@ -51,7 +51,7 @@ function escape_with(str, use) end else while i < i_next - write(out, hex_string(Vector{UInt8}(str)[i])) + write(out, hex_string(codeunits(str)[i])) i += 1 end end @@ -61,4 +61,4 @@ function escape_with(str, use) end escape(str) = escape_with(str, unescaped) -escape_form(str) = replace(escape_with(str, unescaped_form), " ", "+") +escape_form(str) = replace(escape_with(str, unescaped_form), " " => "+") diff --git a/src/parser.jl b/src/parser.jl index 4bbc13f..a9b2174 100644 --- a/src/parser.jl +++ b/src/parser.jl @@ -1,11 +1,17 @@ +if isdefined(Base, :isnumeric) + _isalnum(c) = isalpha(c) || isnumeric(c) +else + const _isalnum = Base.isalnum +end + is_url_char(c) = ((@assert UInt32(c) < 0x80); 'A' <= c <= '~' || '$' <= c <= '>' || c == '\f' || c == '\t') is_mark(c) = (c == '-') || (c == '_') || (c == '.') || (c == '!') || (c == '~') || (c == '*') || (c == '\'') || (c == '(') || (c == ')') -is_userinfo_char(c) = isalnum(c) || is_mark(c) || (c == '%') || (c == ';') || +is_userinfo_char(c) = _isalnum(c) || is_mark(c) || (c == '%') || (c == ';') || (c == ':') || (c == '&') || (c == '+') || (c == '$' || c == ',') isnum(c) = ('0' <= c <= '9') ishex(c) = (isnum(c) || 'a' <= lowercase(c) <= 'f') -is_host_char(c) = isalnum(c) || (c == '.') || (c == '-') || (c == '_') || (c == "~") +is_host_char(c) = _isalnum(c) || (c == '.') || (c == '-') || (c == '_') || (c == "~") struct URI @@ -133,7 +139,7 @@ function parse_authority(authority,seen_at) error("Unexpected state $state") end end - (host, UInt16(port == "" ? 0 : parse(Int,port,10)), user) + (host, UInt16(port == "" ? 0 : _parse(Int, port, 10)), user) end function parse_url(url) diff --git a/src/utils.jl b/src/utils.jl index 5b9b2e1..046799e 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -8,7 +8,7 @@ function userinfo(uri::URI) Base.warn_once("Use of the format user:password is deprecated (rfc3986)") uinfo = uri.userinfo - sep = search(uinfo, ':') + sep = findfirst(equalto(':'), uinfo) l = length(uinfo) username = uinfo[1:(sep-1)] password = ((sep == l) || (sep == 0)) ? "" : uinfo[(sep+1):l] @@ -61,7 +61,9 @@ const uses_fragment = ["hdfs", "ftp", "hdl", "http", "gopher", "news", "nntp", " function isvalid(uri::URI) scheme = uri.scheme isempty(scheme) && error("Can not validate relative URI") - if ((scheme in non_hierarchical) && (search(uri.path, '/') > 1)) || # path hierarchy not allowed + slash = findfirst(equalto('/'), uri.path) + hasslash = slash !== nothing && slash > 1 # For 0.6 compatibility + if ((scheme in non_hierarchical) && hasslash) || # path hierarchy not allowed (!(scheme in uses_query) && !isempty(uri.query)) || # query component not allowed (!(scheme in uses_fragment) && !isempty(uri.fragment)) || # fragment identifier component not allowed (!(scheme in uses_authority) && (!isempty(uri.host) || (0 != uri.port) || !isempty(uri.userinfo))) # authority component not allowed diff --git a/test/runtests.jl b/test/runtests.jl index 027e409..581f6ef 100755 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -15,6 +15,7 @@ urls = ["hdfs://user:password@hdfshost:9000/root/folder/file.csv#frag", failed = 0 for url in urls + global failed u = URI(url) if !(string(u) == url) || !isvalid(u) failed += 1