Commit 9931ef4a authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'fix-escaped-text-replacement' into 'master'

Fix escaped text replacement

Closes #37724

See merge request gitlab-org/gitlab-ce!14193
parents 27319ffc 1d30e5e9
...@@ -1280,10 +1280,12 @@ export default class Notes { ...@@ -1280,10 +1280,12 @@ export default class Notes {
* Get data from Form attributes to use for saving/submitting comment. * Get data from Form attributes to use for saving/submitting comment.
*/ */
getFormData($form) { getFormData($form) {
const content = $form.find('.js-note-text').val();
return { return {
formData: $form.serialize(), formData: $form.serialize(),
formContent: _.escape($form.find('.js-note-text').val()), formContent: _.escape(content),
formAction: $form.attr('action'), formAction: $form.attr('action'),
formContentOriginal: content,
}; };
} }
...@@ -1415,7 +1417,7 @@ export default class Notes { ...@@ -1415,7 +1417,7 @@ export default class Notes {
const isMainForm = $form.hasClass('js-main-target-form'); const isMainForm = $form.hasClass('js-main-target-form');
const isDiscussionForm = $form.hasClass('js-discussion-note-form'); const isDiscussionForm = $form.hasClass('js-discussion-note-form');
const isDiscussionResolve = $submitBtn.hasClass('js-comment-resolve-button'); const isDiscussionResolve = $submitBtn.hasClass('js-comment-resolve-button');
const { formData, formContent, formAction } = this.getFormData($form); const { formData, formContent, formAction, formContentOriginal } = this.getFormData($form);
let noteUniqueId; let noteUniqueId;
let systemNoteUniqueId; let systemNoteUniqueId;
let hasQuickActions = false; let hasQuickActions = false;
...@@ -1574,7 +1576,7 @@ export default class Notes { ...@@ -1574,7 +1576,7 @@ export default class Notes {
$form = $notesContainer.parent().find('form'); $form = $notesContainer.parent().find('form');
} }
$form.find('.js-note-text').val(formContent); $form.find('.js-note-text').val(formContentOriginal);
this.reenableTargetFormSubmitButton(e); this.reenableTargetFormSubmitButton(e);
this.addNoteError($form); this.addNoteError($form);
}); });
......
...@@ -103,6 +103,16 @@ import '~/notes'; ...@@ -103,6 +103,16 @@ import '~/notes';
$('.js-comment-button').click(); $('.js-comment-button').click();
expect(this.autoSizeSpy).toHaveBeenTriggered(); expect(this.autoSizeSpy).toHaveBeenTriggered();
}); });
it('should not place escaped text in the comment box in case of error', function() {
const deferred = $.Deferred();
spyOn($, 'ajax').and.returnValue(deferred.promise());
$(textarea).text('A comment with `markup`.');
deferred.reject();
$('.js-comment-button').click();
expect($(textarea).val()).toEqual('A comment with `markup`.');
});
}); });
describe('updateNote', () => { describe('updateNote', () => {
......
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