aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2022-04-26 11:14:01 +0800
committerGitHub <noreply@github.com>2022-04-26 11:14:01 +0800
commitfef26c159c7f426d7f6331b31e6d4119e47a9188 (patch)
treef281167866f9f0fce16ee97317a501a6a1d2f20b /web_src/js
parent741c55b4eacafa2e3e55ccd634cd3511920dfc98 (diff)
downloadgitea-fef26c159c7f426d7f6331b31e6d4119e47a9188.tar.gz
gitea-fef26c159c7f426d7f6331b31e6d4119e47a9188.zip
Fix two UI bugs: JS error in imagediff.js, 500 error in diff/compare.tmpl
Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'web_src/js')
-rw-r--r--web_src/js/features/imagediff.js15
1 files changed, 11 insertions, 4 deletions
diff --git a/web_src/js/features/imagediff.js b/web_src/js/features/imagediff.js
index 6fd2ba6c36..1745331768 100644
--- a/web_src/js/features/imagediff.js
+++ b/web_src/js/features/imagediff.js
@@ -4,10 +4,12 @@ function getDefaultSvgBoundsIfUndefined(svgXml, src) {
const DefaultSize = 300;
const MaxSize = 99999;
- const svg = svgXml.rootElement;
-
- const width = svg.width.baseVal;
- const height = svg.height.baseVal;
+ const svg = svgXml.documentElement;
+ const width = svg?.width?.baseVal;
+ const height = svg?.height?.baseVal;
+ if (width === undefined || height === undefined) {
+ return null; // in case some svg is invalid or doesn't have the width/height
+ }
if (width.unitType === SVGLength.SVG_LENGTHTYPE_PERCENTAGE || height.unitType === SVGLength.SVG_LENGTHTYPE_PERCENTAGE) {
const img = new Image();
img.src = src;
@@ -29,6 +31,7 @@ function getDefaultSvgBoundsIfUndefined(svgXml, src) {
height: DefaultSize
};
}
+ return null;
}
export default function initImageDiff() {
@@ -88,6 +91,10 @@ export default function initImageDiff() {
info.$image.on('load', () => {
info.loaded = true;
setReadyIfLoaded();
+ }).on('error', () => {
+ info.loaded = true;
+ setReadyIfLoaded();
+ info.$boundsInfo.text('(image error)');
});
info.$image.attr('src', info.path);