Commit b0e398f4 authored by Simon Knox's avatar Simon Knox

Merge branch...

Merge branch '241923-remove-v-html-from-app-assets-javascripts-ide-components-commit_sidebar-actions-vue' into 'master'

Replace v-html with gl-sprintf in app/assets/javascripts/ide/components/commit_sidebar/actions.vue

Closes #241923

See merge request gitlab-org/gitlab!41511
parents bea93ce4 d5e3f4bd
<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