From f7cbe5f03bfdb3eb2ee9b2db2655cd17d02320c9 Mon Sep 17 00:00:00 2001 From: Sam O'Connor Date: Wed, 17 Jan 2018 19:32:17 +1100 Subject: [PATCH] Quick hack to work around https://github.com/JuliaLang/julia/pull/25472 --- src/Pairs.jl | 11 ++++++----- src/Parsers.jl | 5 +++-- src/URIs.jl | 4 +++- src/compat.jl | 6 ++++++ src/cookies.jl | 4 +++- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/Pairs.jl b/src/Pairs.jl index b48f71b60..a9b33096b 100644 --- a/src/Pairs.jl +++ b/src/Pairs.jl @@ -2,6 +2,7 @@ module Pairs export defaultbyfirst, setbyfirst, getbyfirst, setkv, getkv, rmkv +import ..compat_findfirst """ setbyfirst(collection, item) -> item @@ -13,7 +14,7 @@ Otherwise the new `item` is inserted at the end of the `collection`. function setbyfirst(c, item, eq = ==) k = first(item) - if (i = findfirst(x->eq(first(x), k), c)) > 0 + if (i = compat_findfirst(x->eq(first(x), k), c)) > 0 c[i] = item else push!(c, item) @@ -29,7 +30,7 @@ Get `item` from collection where `first(item)` matches `key`. """ function getbyfirst(c, k, default=nothing, eq = ==) - i = findfirst(x->eq(first(x), k), c) + i = compat_findfirst(x->eq(first(x), k), c) return i > 0 ? c[i] : default end @@ -43,7 +44,7 @@ insert the new `item` at the end of the `collection`. function defaultbyfirst(c, item, eq = ==) k = first(item) - if (i = findfirst(x->eq(first(x), k), c)) == 0 + if (i = compat_findfirst(x->eq(first(x), k), c)) == 0 push!(c, item) end return @@ -67,7 +68,7 @@ where `first(item) == key` and `value = item[2]` """ function getkv(c, k, default=nothing) - i = findfirst(x->first(x) == k, c) + i = compat_findfirst(x->first(x) == k, c) return i > 0 ? c[i][2] : default end @@ -79,7 +80,7 @@ Remove `key` from `collection` of key/value `Pairs`. """ function rmkv(c, k, default=nothing) - i = findfirst(x->first(x) == k, c) + i = compat_findfirst(x->first(x) == k, c) if i > 0 deleteat!(c, i) end diff --git a/src/Parsers.jl b/src/Parsers.jl index d678dc1d3..9a4515bf5 100644 --- a/src/Parsers.jl +++ b/src/Parsers.jl @@ -38,6 +38,7 @@ import MbedTLS.SSLContext import ..@debug, ..@debugshow, ..DEBUG_LEVEL import ..@require, ..precondition_error +import ..compat_findfirst include("consts.jl") include("parseutils.jl") @@ -465,7 +466,7 @@ function parseheaders(onheader::Function #=f(::Pair{String,String}) =#, end @passert p <= len + 1 - write(parser.valuebuffer, view(bytes, start:p-1)) + write(parser.valuebuffer, collect(view(bytes, start:p-1))) if p_state >= s_req_http_start parser.message.target = take!(parser.valuebuffer) @@ -603,7 +604,7 @@ function parseheaders(onheader::Function #=f(::Pair{String,String}) =#, c = lower(ch) @debugshow 4 h - crlf = findfirst(x->(x == bCR || x == bLF), view(bytes, p:len)) + crlf = compat_findfirst(x->(x == bCR || x == bLF), view(bytes, p:len)) p = crlf == 0 ? len : p + crlf - 2 p += 1 diff --git a/src/URIs.jl b/src/URIs.jl index b116d636a..f3457b46e 100644 --- a/src/URIs.jl +++ b/src/URIs.jl @@ -4,6 +4,7 @@ import Base.== import ..@require, ..precondition_error import ..@ensure, ..postcondition_error +import ..compat_search include("urlparser.jl") @@ -175,10 +176,11 @@ const uses_query = ["http", "wais", "imap", "https", "shttp", "mms", "gopher", " const uses_fragment = ["hdfs", "ftp", "hdl", "http", "gopher", "news", "nntp", "wais", "https", "shttp", "snews", "file", "prospero"] "checks if a `HTTP.URI` is valid" + function Base.isvalid(uri::URI) sch = uri.scheme isempty(sch) && throw(ArgumentError("can not validate relative URI")) - if ((sch in non_hierarchical) && (search(uri.path, '/') > 1)) || # path hierarchy not allowed + if ((sch in non_hierarchical) && (compat_search(uri.path, '/') > 1)) || # path hierarchy not allowed (!(sch in uses_query) && !isempty(uri.query)) || # query component not allowed (!(sch in uses_fragment) && !isempty(uri.fragment)) || # fragment identifier component not allowed (!(sch in uses_authority) && (!isempty(uri.host) || ("" != uri.port) || !isempty(uri.userinfo))) # authority component not allowed diff --git a/src/compat.jl b/src/compat.jl index 45e16b4a4..35b86ff41 100644 --- a/src/compat.jl +++ b/src/compat.jl @@ -4,12 +4,18 @@ using Distributed import Dates + compat_search(a...) = (r = search(a...); r === nothing ? 0 : r) + compat_findfirst(a...) = (r = findfirst(a...); r === nothing ? 0 : r) + else # Julia v0.6 eval(:(module Base64 end)) const Dates = Base.Dates const Distributed = Base.Distributed + const compat_search = search + const compat_findfirst = findfirst + pairs(x) = [k => v for (k,v) in x] Base.SubString(s) = SubString(s, 1) diff --git a/src/cookies.jl b/src/cookies.jl index baa970b5a..8695daf52 100644 --- a/src/cookies.jl +++ b/src/cookies.jl @@ -37,6 +37,8 @@ import ..Dates import Base.== import ..URIs.isurlchar using ..pairs +import ..compat_search + """ Cookie() @@ -163,7 +165,7 @@ function readsetcookie(host, cookie) parts[x] = strip(parts[x]) length(parts[x]) == 0 && continue attr, val = parts[x], "" - j = search(parts[x], '=') + j = compat_search(parts[x], '=') if j > 0 attr, val = attr[1:j-1], attr[j+1:end] end