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

Use encodeSaferURL utility to render image diff

parent 00a126aa
<script>
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 {
props: {
......@@ -43,6 +44,9 @@ export default {
hasDimensions() {
return this.width && this.height;
},
safePath() {
return encodeSaferUrl(this.path);
},
},
beforeDestroy() {
window.removeEventListener('resize', this.resizeThrottled, false);
......@@ -84,7 +88,7 @@ export default {
<template>
<div data-testid="image-viewer" data-qa-selector="image_viewer_container">
<div :class="innerCssClasses" class="position-relative">
<img ref="contentImg" :src="path" @load="onImgLoad" />
<img ref="contentImg" :src="safePath" @load="onImgLoad" />
<slot
name="image-overlay"
:rendered-width="renderedWidth"
......
......@@ -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