Skip to content

Commit a567ecf

Browse files
committed
Fix ;-escaping in the final history search segment
Let's also avoid copying the entirety of `str` when dropping escaped characters while I'm at it.
1 parent c5eba24 commit a567ecf

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

stdlib/REPL/src/History/resumablefiltering.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,27 @@ function ConditionSet(spec::S) where {S <: AbstractString}
164164
elseif chr == '\\'
165165
escaped = true
166166
elseif chr == FILTER_SEPARATOR
167-
str = SubString(spec, mark:prevind(spec, pos))
168-
if !isempty(dropbytes)
169-
str = SubString(convert(S, String(deleteat!(collect(codeunits(str)), dropbytes))))
167+
str = if isempty(dropbytes)
168+
SubString(spec, mark:prevind(spec, pos))
169+
else
170+
subbytes = deleteat!(codeunits(spec)[mark:pos-1], dropbytes)
170171
empty!(dropbytes)
172+
SubString(convert(S, String(subbytes)))
171173
end
172174
addcond!(cset, lstrip(str))
173175
mark = pos + 1
174176
end
175177
pos = nextind(spec, pos)
176178
end
177179
if mark <= lastind
178-
str = SubString(spec, mark:prevind(spec, pos))
179-
if !isempty(dropbytes)
180-
str = SubString(convert(S, String(deleteat!(collect(codeunits(str)), dropbytes))))
180+
str = if isempty(dropbytes)
181+
SubString(spec, mark)
182+
else
183+
subbytes = deleteat!(codeunits(spec)[mark:end], dropbytes)
184+
empty!(dropbytes)
185+
SubString(convert(S, String(subbytes)))
181186
end
182-
addcond!(cset, lstrip(SubString(spec, mark:lastind)))
187+
addcond!(cset, lstrip(str))
183188
end
184189
cset
185190
end

stdlib/REPL/test/history.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ end
231231
cset = ConditionSet("hello\\;world;=exact")
232232
@test cset.words == [SubString("hello;world")]
233233
@test cset.exacts == [SubString("exact")]
234+
cset = ConditionSet("1 \\; 2")
235+
@test cset.words == [SubString("1 ; 2")]
234236
end
235237
@testset "Complex query" begin
236238
cset = ConditionSet("some = words ;; !error ; julia> ;/^def.*;")

0 commit comments

Comments
 (0)