Commit d5e3f4bd authored by Takuya Noguchi's avatar Takuya Noguchi

Replace v-html with gl-sprintf in ide/.../commit_sidebar/actions.vue

Signed-off-by: default avatarTakuya Noguchi <takninnovationresearch@gmail.com>
parent 60e36e72
<script> <script>
/* eslint-disable vue/no-v-html */
import { escape } from 'lodash'; import { escape } from 'lodash';
import { mapState, mapGetters, createNamespacedHelpers } from 'vuex'; import { mapState, mapGetters, createNamespacedHelpers } from 'vuex';
import { sprintf, s__ } from '~/locale'; import { GlSprintf } from '@gitlab/ui';
import { s__ } from '~/locale';
import consts from '../../stores/modules/commit/constants'; import consts from '../../stores/modules/commit/constants';
import RadioGroup from './radio_group.vue'; import RadioGroup from './radio_group.vue';
import NewMergeRequestOption from './new_merge_request_option.vue'; import NewMergeRequestOption from './new_merge_request_option.vue';
...@@ -13,6 +13,7 @@ const { mapState: mapCommitState, mapActions: mapCommitActions } = createNamespa ...@@ -13,6 +13,7 @@ const { mapState: mapCommitState, mapActions: mapCommitActions } = createNamespa
export default { export default {
components: { components: {
GlSprintf,
RadioGroup, RadioGroup,
NewMergeRequestOption, NewMergeRequestOption,
}, },
...@@ -20,12 +21,8 @@ export default { ...@@ -20,12 +21,8 @@ export default {
...mapState(['currentBranchId', 'changedFiles', 'stagedFiles']), ...mapState(['currentBranchId', 'changedFiles', 'stagedFiles']),
...mapCommitState(['commitAction']), ...mapCommitState(['commitAction']),
...mapGetters(['currentBranch', 'emptyRepo', 'canPushToBranch']), ...mapGetters(['currentBranch', 'emptyRepo', 'canPushToBranch']),
commitToCurrentBranchText() { currentBranchText() {
return sprintf( return escape(this.currentBranchId);
s__('IDE|Commit to %{branchName} branch'),
{ branchName: `<strong class="monospace">${escape(this.currentBranchId)}</strong>` },
false,
);
}, },
containsStagedChanges() { containsStagedChanges() {
return this.changedFiles.length > 0 && this.stagedFiles.length > 0; return this.changedFiles.length > 0 && this.stagedFiles.length > 0;
...@@ -77,11 +74,13 @@ export default { ...@@ -77,11 +74,13 @@ export default {
:disabled="!canPushToBranch" :disabled="!canPushToBranch"
:title="$options.currentBranchPermissionsTooltip" :title="$options.currentBranchPermissionsTooltip"
> >
<span <span class="ide-option-label" data-qa-selector="commit_to_current_branch_radio">
class="ide-option-label" <gl-sprintf :message="s__('IDE|Commit to %{branchName} branch')">
data-qa-selector="commit_to_current_branch_radio" <template #branchName>
v-html="commitToCurrentBranchText" <strong class="monospace">{{ currentBranchText }}</strong>
></span> </template>
</gl-sprintf>
</span>
</radio-group> </radio-group>
<template v-if="!emptyRepo"> <template v-if="!emptyRepo">
<radio-group <radio-group
......
...@@ -83,12 +83,12 @@ describe('IDE commit sidebar actions', () => { ...@@ -83,12 +83,12 @@ describe('IDE commit sidebar actions', () => {
}); });
}); });
describe('commitToCurrentBranchText', () => { describe('currentBranchText', () => {
it('escapes current branch', () => { it('escapes current branch', () => {
const injectedSrc = '<img src="x" />'; const injectedSrc = '<img src="x" />';
createComponent({ currentBranchId: injectedSrc }); createComponent({ currentBranchId: injectedSrc });
expect(vm.commitToCurrentBranchText).not.toContain(injectedSrc); expect(vm.currentBranchText).not.toContain(injectedSrc);
}); });
}); });
......
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