Skip to content

Commit f7cbe5f

Browse files
committed
Quick hack to work around JuliaLang/julia#25472
1 parent 68e3a41 commit f7cbe5f

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

src/Pairs.jl

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Pairs
22

33
export defaultbyfirst, setbyfirst, getbyfirst, setkv, getkv, rmkv
44

5+
import ..compat_findfirst
56

67
"""
78
setbyfirst(collection, item) -> item
@@ -13,7 +14,7 @@ Otherwise the new `item` is inserted at the end of the `collection`.
1314

1415
function setbyfirst(c, item, eq = ==)
1516
k = first(item)
16-
if (i = findfirst(x->eq(first(x), k), c)) > 0
17+
if (i = compat_findfirst(x->eq(first(x), k), c)) > 0
1718
c[i] = item
1819
else
1920
push!(c, item)
@@ -29,7 +30,7 @@ Get `item` from collection where `first(item)` matches `key`.
2930
"""
3031

3132
function getbyfirst(c, k, default=nothing, eq = ==)
32-
i = findfirst(x->eq(first(x), k), c)
33+
i = compat_findfirst(x->eq(first(x), k), c)
3334
return i > 0 ? c[i] : default
3435
end
3536

@@ -43,7 +44,7 @@ insert the new `item` at the end of the `collection`.
4344

4445
function defaultbyfirst(c, item, eq = ==)
4546
k = first(item)
46-
if (i = findfirst(x->eq(first(x), k), c)) == 0
47+
if (i = compat_findfirst(x->eq(first(x), k), c)) == 0
4748
push!(c, item)
4849
end
4950
return
@@ -67,7 +68,7 @@ where `first(item) == key` and `value = item[2]`
6768
"""
6869

6970
function getkv(c, k, default=nothing)
70-
i = findfirst(x->first(x) == k, c)
71+
i = compat_findfirst(x->first(x) == k, c)
7172
return i > 0 ? c[i][2] : default
7273
end
7374

@@ -79,7 +80,7 @@ Remove `key` from `collection` of key/value `Pairs`.
7980
"""
8081

8182
function rmkv(c, k, default=nothing)
82-
i = findfirst(x->first(x) == k, c)
83+
i = compat_findfirst(x->first(x) == k, c)
8384
if i > 0
8485
deleteat!(c, i)
8586
end

src/Parsers.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import MbedTLS.SSLContext
3838

3939
import ..@debug, ..@debugshow, ..DEBUG_LEVEL
4040
import ..@require, ..precondition_error
41+
import ..compat_findfirst
4142

4243
include("consts.jl")
4344
include("parseutils.jl")
@@ -465,7 +466,7 @@ function parseheaders(onheader::Function #=f(::Pair{String,String}) =#,
465466
end
466467
@passert p <= len + 1
467468

468-
write(parser.valuebuffer, view(bytes, start:p-1))
469+
write(parser.valuebuffer, collect(view(bytes, start:p-1)))
469470

470471
if p_state >= s_req_http_start
471472
parser.message.target = take!(parser.valuebuffer)
@@ -603,7 +604,7 @@ function parseheaders(onheader::Function #=f(::Pair{String,String}) =#,
603604
c = lower(ch)
604605

605606
@debugshow 4 h
606-
crlf = findfirst(x->(x == bCR || x == bLF), view(bytes, p:len))
607+
crlf = compat_findfirst(x->(x == bCR || x == bLF), view(bytes, p:len))
607608
p = crlf == 0 ? len : p + crlf - 2
608609

609610
p += 1

src/URIs.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Base.==
44

55
import ..@require, ..precondition_error
66
import ..@ensure, ..postcondition_error
7+
import ..compat_search
78

89

910
include("urlparser.jl")
@@ -175,10 +176,11 @@ const uses_query = ["http", "wais", "imap", "https", "shttp", "mms", "gopher", "
175176
const uses_fragment = ["hdfs", "ftp", "hdl", "http", "gopher", "news", "nntp", "wais", "https", "shttp", "snews", "file", "prospero"]
176177

177178
"checks if a `HTTP.URI` is valid"
179+
178180
function Base.isvalid(uri::URI)
179181
sch = uri.scheme
180182
isempty(sch) && throw(ArgumentError("can not validate relative URI"))
181-
if ((sch in non_hierarchical) && (search(uri.path, '/') > 1)) || # path hierarchy not allowed
183+
if ((sch in non_hierarchical) && (compat_search(uri.path, '/') > 1)) || # path hierarchy not allowed
182184
(!(sch in uses_query) && !isempty(uri.query)) || # query component not allowed
183185
(!(sch in uses_fragment) && !isempty(uri.fragment)) || # fragment identifier component not allowed
184186
(!(sch in uses_authority) && (!isempty(uri.host) || ("" != uri.port) || !isempty(uri.userinfo))) # authority component not allowed

src/compat.jl

+6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44
using Distributed
55
import Dates
66

7+
compat_search(a...) = (r = search(a...); r === nothing ? 0 : r)
8+
compat_findfirst(a...) = (r = findfirst(a...); r === nothing ? 0 : r)
9+
710
else # Julia v0.6
811

912
eval(:(module Base64 end))
1013
const Dates = Base.Dates
1114
const Distributed = Base.Distributed
1215

16+
const compat_search = search
17+
const compat_findfirst = findfirst
18+
1319
pairs(x) = [k => v for (k,v) in x]
1420

1521
Base.SubString(s) = SubString(s, 1)

src/cookies.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import ..Dates
3737
import Base.==
3838
import ..URIs.isurlchar
3939
using ..pairs
40+
import ..compat_search
41+
4042

4143
"""
4244
Cookie()
@@ -163,7 +165,7 @@ function readsetcookie(host, cookie)
163165
parts[x] = strip(parts[x])
164166
length(parts[x]) == 0 && continue
165167
attr, val = parts[x], ""
166-
j = search(parts[x], '=')
168+
j = compat_search(parts[x], '=')
167169
if j > 0
168170
attr, val = attr[1:j-1], attr[j+1:end]
169171
end

0 commit comments

Comments
 (0)