Skip to content

Commit 68e1b6a

Browse files
committed
fix
1 parent 21a1d76 commit 68e1b6a

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

modules/typesniffer/typesniffer.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ const (
2424
)
2525

2626
var (
27-
svgTagRegex = regexp.MustCompile(`(?si)\A\s*(?:(<!--.*?-->|<!DOCTYPE\s+svg([\s:]+.*?>|>))\s*)*<svg[\s>\/]`)
28-
svgTagInXMLRegex = regexp.MustCompile(`(?si)\A<\?xml\b.*?\?>\s*(?:(<!--.*?-->|<!DOCTYPE\s+svg([\s:]+.*?>|>))\s*)*<svg[\s>\/]`)
27+
svgComment = regexp.MustCompile(`(?s)<!--.*?-->`)
28+
svgTagRegex = regexp.MustCompile(`(?si)\A\s*(?:(<!DOCTYPE\s+svg([\s:]+.*?>|>))\s*)*<svg[\s>/]`)
29+
svgTagInXMLRegex = regexp.MustCompile(`(?si)\A<\?xml\b.*?\?>\s*(?:(<!DOCTYPE\s+svg([\s:]+.*?>|>))\s*)*<svg[\s>/]`)
2930
)
3031

3132
// SniffedType contains information about a blobs type.
@@ -91,10 +92,19 @@ func DetectContentType(data []byte) SniffedType {
9192
data = data[:sniffLen]
9293
}
9394

94-
if (strings.Contains(ct, "text/plain") || strings.Contains(ct, "text/html")) && svgTagRegex.Match(data) ||
95-
strings.Contains(ct, "text/xml") && svgTagInXMLRegex.Match(data) {
96-
// SVG is unsupported. https://github.com/golang/go/issues/15888
97-
ct = SvgMimeType
95+
// SVG is unsupported by http.DetectContentType, https://github.com/golang/go/issues/15888
96+
97+
if strings.Contains(ct, "text/plain") || strings.Contains(ct, "text/html") {
98+
dataNoComment := svgComment.ReplaceAll(data, nil)
99+
if svgTagRegex.Match(dataNoComment) {
100+
ct = SvgMimeType
101+
}
102+
}
103+
if strings.Contains(ct, "text/xml") {
104+
dataNoComment := svgComment.ReplaceAll(data, nil)
105+
if svgTagInXMLRegex.Match(dataNoComment) {
106+
ct = SvgMimeType
107+
}
98108
}
99109

100110
return SniffedType{ct}

modules/typesniffer/typesniffer_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ func TestIsSvgImage(t *testing.T) {
6868
assert.False(t, DetectContentType([]byte(`<?xml version="1.0" encoding="UTF-8"?>
6969
<!-- <svg></svg> inside comment -->
7070
<foo></foo>`)).IsSvgImage())
71+
72+
assert.False(t, DetectContentType([]byte(`
73+
<!-- comment1 -->
74+
<div>
75+
<!-- comment2 -->
76+
<svg></svg>
77+
</div>
78+
`)).IsSvgImage())
79+
80+
assert.False(t, DetectContentType([]byte(`
81+
<!-- comment1
82+
-->
83+
<div>
84+
<!-- comment2
85+
-->
86+
<svg></svg>
87+
</div>
88+
`)).IsSvgImage())
89+
assert.False(t, DetectContentType([]byte(`<html><body><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg></svg></body></html>`)).IsSvgImage())
90+
assert.False(t, DetectContentType([]byte(`<html><body><?xml version="1.0" encoding="UTF-8"?><svg></svg></body></html>`)).IsSvgImage())
7191
}
7292

7393
func TestIsPDF(t *testing.T) {

web_src/js/features/imagediff.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ export function initImageDiff() {
129129
initOverlay(createContext($imageAfter[2], $imageBefore[2]));
130130
}
131131

132-
hideElem($container.find('> .loader'));
133132
$container.find('> .gt-hidden').removeClass('gt-hidden');
133+
hideElem($container.find('.ui.loader'));
134134
}
135135

136136
function initSideBySide(sizes) {
@@ -155,7 +155,7 @@ export function initImageDiff() {
155155
height: sizes.size1.height * factor
156156
});
157157
sizes.image1.parent().css({
158-
margin: `${sizes.ratio[1] * factor + 15}px ${sizes.ratio[0] * factor}px ${sizes.ratio[1] * factor}px`,
158+
margin: `10px auto`,
159159
width: sizes.size1.width * factor + 2,
160160
height: sizes.size1.height * factor + 2
161161
});
@@ -164,7 +164,7 @@ export function initImageDiff() {
164164
height: sizes.size2.height * factor
165165
});
166166
sizes.image2.parent().css({
167-
margin: `${sizes.ratio[3] * factor}px ${sizes.ratio[2] * factor}px`,
167+
margin: `10px auto`,
168168
width: sizes.size2.width * factor + 2,
169169
height: sizes.size2.height * factor + 2
170170
});
@@ -255,13 +255,10 @@ export function initImageDiff() {
255255
width: sizes.size2.width * factor + 2,
256256
height: sizes.size2.height * factor + 2
257257
});
258+
258259
sizes.image2.parent().parent().css({
259260
width: sizes.max.width * factor + 2,
260-
height: sizes.max.height * factor + 2
261-
});
262-
$container.find('.onion-skin').css({
263-
width: sizes.max.width * factor + 2,
264-
height: sizes.max.height * factor + 4
261+
height: sizes.max.height * factor + 2 + 20,
265262
});
266263

267264
const $range = $container.find("input[type='range']");

web_src/less/features/imagediff.less

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.image-diff-container {
22
text-align: center;
3-
padding: 30px 0;
3+
padding: 1em 0;
44

55
img {
66
border: 1px solid var(--color-primary-light-7);
@@ -22,6 +22,7 @@
2222
display: inline-block;
2323
line-height: 0;
2424
vertical-align: top;
25+
margin: 0 1em;
2526

2627
.side-header {
2728
font-weight: bold;
@@ -98,7 +99,7 @@
9899
}
99100

100101
input {
101-
width: 300px;
102+
max-width: 300px;
102103
}
103104
}
104105
}

0 commit comments

Comments
 (0)