Commit 2cac4e4e authored by Thomas Randolph's avatar Thomas Randolph

Use encodeSaferURL utility to render image diff

parent 00a126aa
<script> <script>
import { throttle } from 'lodash'; import { throttle } from 'lodash';
import { numberToHumanSize } from '../../../../lib/utils/number_utils'; import { numberToHumanSize } from '~/lib/utils/number_utils';
import { encodeSaferUrl } from '~/lib/utils/url_utility';
export default { export default {
props: { props: {
...@@ -43,6 +44,9 @@ export default { ...@@ -43,6 +44,9 @@ export default {
hasDimensions() { hasDimensions() {
return this.width && this.height; return this.width && this.height;
}, },
safePath() {
return encodeSaferUrl(this.path);
},
}, },
beforeDestroy() { beforeDestroy() {
window.removeEventListener('resize', this.resizeThrottled, false); window.removeEventListener('resize', this.resizeThrottled, false);
...@@ -84,7 +88,7 @@ export default { ...@@ -84,7 +88,7 @@ export default {
<template> <template>
<div data-testid="image-viewer" data-qa-selector="image_viewer_container"> <div data-testid="image-viewer" data-qa-selector="image_viewer_container">
<div :class="innerCssClasses" class="position-relative"> <div :class="innerCssClasses" class="position-relative">
<img ref="contentImg" :src="path" @load="onImgLoad" /> <img ref="contentImg" :src="safePath" @load="onImgLoad" />
<slot <slot
name="image-overlay" name="image-overlay"
:rendered-width="renderedWidth" :rendered-width="renderedWidth"
......
...@@ -33,4 +33,14 @@ describe('Image Viewer', () => { ...@@ -33,4 +33,14 @@ describe('Image Viewer', () => {
}, },
); );
}); });
describe('file path', () => {
it('should output a valid URL path for the image', () => {
wrapper = mount(ImageViewer, {
propsData: { path: '/url/hello#1.jpg' },
});
expect(wrapper.find('img').attributes('src')).toBe('/url/hello%231.jpg');
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment