• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JuliaLang / julia / #37917

27 Sep 2024 02:34AM UTC coverage: 87.243% (-0.5%) from 87.72%
#37917

push

local

web-flow
inference: add missing `TypeVar` handling for `instanceof_tfunc` (#55884)

I thought these sort of problems had been addressed by d60f92c, but it
seems some were missed. Specifically, `t.a` and `t.b` from `t::Union`
could be `TypeVar`, and if they are passed to a subroutine or recursed
without being unwrapped or rewrapped, errors like JuliaLang/julia#55882
could occur.

This commit resolves the issue by calling `unwraptv` in the `Union`
handling within `instanceof_tfunc`. I also found a similar issue inside
`nfields_tfunc`, so that has also been fixed, and test cases have been
added. While I haven't been able to make up a test case specifically for
the fix in `instanceof_tfunc`, I have confirmed that this commit
certainly fixes the issue reported in JuliaLang/julia#55882.

- fixes JuliaLang/julia#55882

4 of 4 new or added lines in 1 file covered. (100.0%)

448 existing lines in 25 files now uncovered.

77170 of 88454 relevant lines covered (87.24%)

16041082.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

59.8
/stdlib/Markdown/src/render/html.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
include("rich.jl")
4

5
# Utils
6

7
function withtag(f, io::IO, tag, attrs...)
120✔
8
    print(io, "<$tag")
120✔
9
    for (attr, value) in attrs
120✔
10
        print(io, " ")
30✔
11
        htmlesc(io, attr)
30✔
12
        print(io, "=\"")
30✔
13
        htmlesc(io, value)
30✔
14
        print(io, "\"")
30✔
15
    end
30✔
16
    f === nothing && return print(io, " />")
120✔
17

18
    print(io, ">")
120✔
19
    f()
120✔
20
    print(io, "</$tag>")
120✔
21
end
22

UNCOV
23
tag(io::IO, tag, attrs...) = withtag(nothing, io, tag, attrs...)
×
24

25
const _htmlescape_chars = Dict('<'=>"&lt;",   '>'=>"&gt;",
26
                               '"'=>"&quot;", '&'=>"&amp;",
27
                               # ' '=>"&nbsp;",
28
                               )
29
for ch in "'`!\$%()=+{}[]"
30
    _htmlescape_chars[ch] = "&#$(Int(ch));"
31
end
32

33
function htmlesc(io::IO, s::AbstractString)
180✔
34
    # s1 = replace(s, r"&(?!(\w+|\#\d+);)" => "&amp;")
35
    for ch in s
360✔
36
        print(io, get(_htmlescape_chars, ch, ch))
3,406✔
37
    end
3,296✔
38
end
39
function htmlesc(io::IO, s::Symbol)
40
    htmlesc(io, string(s))
30✔
41
end
42
function htmlesc(io::IO, xs::Union{AbstractString,Symbol}...)
×
43
    for s in xs
×
44
        htmlesc(io, s)
×
45
    end
×
46
end
47
function htmlesc(s::Union{AbstractString,Symbol})
×
48
    sprint(htmlesc, s)
×
49
end
50

51
# Block elements
52

53
function html(io::IO, content::Vector)
32✔
54
    for md in content
32✔
55
        html(io, md)
58✔
56
        println(io)
58✔
57
    end
58✔
58
end
59

60
html(io::IO, md::MD) = html(io, md.content)
30✔
61

62
function html(io::IO, header::Header{l}) where l
16✔
63
    withtag(io, "h$l") do
16✔
64
        htmlinline(io, header.text)
16✔
65
    end
66
end
67

68
function html(io::IO, code::Code)
14✔
69
    withtag(io, :pre) do
14✔
70
        if code.language == "styled"
14✔
71
            code = Code("", String(styled(code.code)))
×
72
        end
73
        maybe_lang = !isempty(code.language) ? Any[:class=>"language-$(code.language)"] : []
26✔
74
        withtag(io, :code, maybe_lang...) do
14✔
75
            htmlesc(io, code.code)
14✔
76
            # TODO should print newline if this is longer than one line ?
77
        end
78
    end
79
end
80

81
function html(io::IO, md::Paragraph)
14✔
82
    withtag(io, :p) do
14✔
83
        htmlinline(io, md.content)
14✔
84
    end
85
end
86

UNCOV
87
function html(io::IO, md::BlockQuote)
×
UNCOV
88
    withtag(io, :blockquote) do
×
UNCOV
89
        println(io)
×
UNCOV
90
        html(io, md.content)
×
91
    end
92
end
93

UNCOV
94
function html(io::IO, f::Footnote)
×
UNCOV
95
    withtag(io, :div, :class => "footnote", :id => "footnote-$(f.id)") do
×
UNCOV
96
        withtag(io, :p, :class => "footnote-title") do
×
UNCOV
97
            print(io, f.id)
×
98
        end
UNCOV
99
        html(io, f.text)
×
100
    end
101
end
102

103
function html(io::IO, md::Admonition)
2✔
104
    withtag(io, :div, :class => "admonition $(md.category)") do
2✔
105
        withtag(io, :p, :class => "admonition-title") do
2✔
106
            print(io, md.title)
2✔
107
        end
108
        html(io, md.content)
2✔
109
    end
110
end
111

UNCOV
112
function html(io::IO, md::List)
×
UNCOV
113
    maybe_attr = md.ordered > 1 ? Any[:start => string(md.ordered)] : []
×
UNCOV
114
    withtag(io, isordered(md) ? :ol : :ul, maybe_attr...) do
×
UNCOV
115
        for item in md.items
×
UNCOV
116
            println(io)
×
UNCOV
117
            withtag(io, :li) do
×
UNCOV
118
                html(io, item)
×
119
            end
UNCOV
120
        end
×
UNCOV
121
        println(io)
×
122
    end
123
end
124

UNCOV
125
function html(io::IO, md::HorizontalRule)
×
UNCOV
126
    tag(io, :hr)
×
127
end
128

UNCOV
129
html(io::IO, x) = tohtml(io, x)
×
130

131
# Inline elements
132

133
function htmlinline(io::IO, content::Vector)
48✔
134
    for x in content
48✔
135
        htmlinline(io, x)
124✔
136
    end
124✔
137
end
138

139
function htmlinline(io::IO, code::Code)
40✔
140
    if code.language == "styled"
40✔
141
        code = Code("", String(styled(code.code)))
×
142
    end
143
    withtag(io, :code) do
40✔
144
        htmlesc(io, code.code)
40✔
145
    end
146
end
147

148
function htmlinline(io::IO, md::Union{Symbol,AbstractString})
66✔
149
    htmlesc(io, md)
66✔
150
end
151

152
function htmlinline(io::IO, md::Bold)
2✔
153
    withtag(io, :strong) do
2✔
154
        htmlinline(io, md.text)
2✔
155
    end
156
end
157

158
function htmlinline(io::IO, md::Italic)
2✔
159
    withtag(io, :em) do
2✔
160
        htmlinline(io, md.text)
2✔
161
    end
162
end
163

164
function htmlinline(io::IO, md::Image)
×
165
    tag(io, :img, :src=>md.url, :alt=>md.alt)
×
166
end
167

168

UNCOV
169
function htmlinline(io::IO, f::Footnote)
×
UNCOV
170
    withtag(io, :a, :href => "#footnote-$(f.id)", :class => "footnote") do
×
UNCOV
171
        print(io, "[", f.id, "]")
×
172
    end
173
end
174

175
function htmlinline(io::IO, link::Link)
14✔
176
    withtag(io, :a, :href=>link.url) do
14✔
177
        htmlinline(io, link.text)
14✔
178
    end
179
end
180

UNCOV
181
function htmlinline(io::IO, br::LineBreak)
×
UNCOV
182
    tag(io, :br)
×
183
end
184

UNCOV
185
htmlinline(io::IO, x) = tohtml(io, x)
×
186

187
# API
188

189
export html
190

191
"""
192
    html([io::IO], md)
193

194
Output the contents of the Markdown object `md` in HTML format, either
195
writing to an (optional) `io` stream or returning a string.
196

197
One can alternatively use `show(io, "text/html", md)` or `repr("text/html", md)`, which
198
differ in that they wrap the output in a `<div class="markdown"> ... </div>` element.
199

200
# Examples
201
```jldoctest
202
julia> html(md"hello _world_")
203
"<p>hello <em>world</em></p>\\n"
204
```
205
"""
206
html(md) = sprint(html, md)
9✔
207

UNCOV
208
function show(io::IO, ::MIME"text/html", md::MD)
×
UNCOV
209
    withtag(io, :div, :class=>"markdown") do
×
UNCOV
210
        html(io, md)
×
211
    end
212
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc