Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disallow unrecognized string/char escapes #22800

Merged
merged 1 commit into from
Jul 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Language changes
* The syntax `1.+2` is deprecated, since it is ambiguous: it could mean either
`1 .+ 2` (the current meaning) or `1. + 2` ([#19089]).

* In string and character literals, backslash `\` may no longer
precede unrecognized escape characters ([#22800]).

Breaking changes
----------------

Expand Down
2 changes: 1 addition & 1 deletion base/markdown/render/html.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const _htmlescape_chars = Dict('<'=>"&lt;", '>'=>"&gt;",
'"'=>"&quot;", '&'=>"&amp;",
# ' '=>"&nbsp;",
)
for ch in "'`!\$\%()=+{}[]"
for ch in "'`!\$%()=+{}[]"
_htmlescape_chars[ch] = "&#$(Int(ch));"
end

Expand Down
6 changes: 3 additions & 3 deletions base/sparse/spqr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,9 @@ end

(\)(F::QRSparse{T}, B::StridedVecOrMat{T}) where {T} = _ldiv_basic(F, B)
"""
(\)(F::QRSparse, B::StridedVecOrMat)
(\\)(F::QRSparse, B::StridedVecOrMat)

Solve the least squares problem ``\min\|Ax - b\|^2`` or the linear system of equations
Solve the least squares problem ``\\min\\|Ax - b\\|^2`` or the linear system of equations
``Ax=b`` when `F` is the sparse QR factorization of ``A``. A basic solution is returned
when the problem is underdetermined.

Expand All @@ -404,7 +404,7 @@ julia> A = sparse([1,2,4], [1,1,1], ones(3), 4, 2)
[2, 1] = 1.0
[4, 1] = 1.0

julia> qrfact(A)\ones(4)
julia> qrfact(A)\\ones(4)
2-element Array{Float64,1}:
1.0
0.0
Expand Down
2 changes: 1 addition & 1 deletion base/statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ cov(X::AbstractMatrix, vardim::Int=1; corrected::Bool=true) =
Compute the covariance between the vectors `x` and `y`. If `corrected` is `true` (the
default), computes ``\\frac{1}{n-1}\\sum_{i=1}^n (x_i-\\bar x) (y_i-\\bar y)^*`` where
``*`` denotes the complex conjugate and `n = length(x) = length(y)`. If `corrected` is
`false`, computes ``\frac{1}{n}\sum_{i=1}^n (x_i-\\bar x) (y_i-\\bar y)^*``.
`false`, computes ``\\frac{1}{n}\\sum_{i=1}^n (x_i-\\bar x) (y_i-\\bar y)^*``.
"""
cov(x::AbstractVector, y::AbstractVector; corrected::Bool=true) =
covm(x, Base.mean(x), y, Base.mean(y); corrected=corrected)
Expand Down
7 changes: 6 additions & 1 deletion src/flisp/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,12 @@ static value_t read_string(fl_context_t *fl_ctx)
i += u8_wc_toutf8(&buf[i], wc);
}
else {
buf[i++] = read_escape_control_char((char)c);
char esc = read_escape_control_char((char)c);
if (esc == (char)c && !strchr("\\'\"$`", esc)) {
free(buf);
lerror(fl_ctx, fl_ctx->ParseError, "read: invalid escape sequence");
}
buf[i++] = esc;
}
}
else {
Expand Down
2 changes: 1 addition & 1 deletion test/libdl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if !Sys.iswindows() || Sys.windows_version() >= Sys.WINDOWS_VISTA_VER
end
end
@test length(filter(dlls) do dl
return ismatch(Regex("^libjulia(?:.*)\.$(Libdl.dlext)(?:\..+)?\$"), basename(dl))
return ismatch(Regex("^libjulia(?:.*)\\.$(Libdl.dlext)(?:\\..+)?\$"), basename(dl))
end) == 1 # look for something libjulia-like (but only one)

# library handle pointer must not be NULL
Expand Down
4 changes: 4 additions & 0 deletions test/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,7 @@ Base.endof(x::CharStr) = endof(x.chars)
@test 'a' * 'b' == "ab"
@test 'a' * "b" * 'c' == "abc"
@test "a" * 'b' * 'c' == "abc"

# unrecognized escapes in string/char literals
@test_throws ParseError parse("\"\\.\"")
@test_throws ParseError parse("\'\\.\'")
4 changes: 0 additions & 4 deletions test/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ for i = 0:0x7f, p = ["","\0","x","xxx","\x7f","\uFF","\uFFF",
@test string(unescape_string(string("\\x",hex(i,3),p))) == hp
end

@test "\z" == unescape_string("\z") == "z"
@test "\X" == unescape_string("\X") == "X"
@test "\AbC" == unescape_string("\AbC") == "AbC"

@test "\0" == unescape_string("\\0")
@test "\1" == unescape_string("\\1")
@test "\7" == unescape_string("\\7")
Expand Down