diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2019-05-06 22:06:00 +0200 |
---|---|---|
committer | Winnie Hellmann <winnie@gitlab.com> | 2019-05-07 23:32:54 +0200 |
commit | 4f1d2bf5a29f28a9f961379d4a3f426454b868b0 (patch) | |
tree | dd72af083f47fcf0d569807c3b8aed42d4254102 | |
parent | 4ce36f3443a3385468fd6fde0ae9f27d54ea1d37 (diff) | |
download | gitlab-ce-4f1d2bf5a29f28a9f961379d4a3f426454b868b0.tar.gz |
Make hasQuickActions statelesswinh-notes-error-handling
-rw-r--r-- | app/assets/javascripts/notes/stores/utils.js | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/app/assets/javascripts/notes/stores/utils.js b/app/assets/javascripts/notes/stores/utils.js index 029fde348fb..ed4cef4a917 100644 --- a/app/assets/javascripts/notes/stores/utils.js +++ b/app/assets/javascripts/notes/stores/utils.js @@ -2,7 +2,8 @@ import AjaxCache from '~/lib/utils/ajax_cache'; import { trimFirstCharOfLineContent } from '~/diffs/store/utils'; import { sprintf, __ } from '~/locale'; -const REGEX_QUICK_ACTIONS = /^\/\w+.*$/gm; +// factory function because global flag makes RegExp stateful +const createQuickActionsRegex = () => /^\/\w+.*$/gm; export const findNoteObjectById = (notes, id) => notes.filter(n => n.id === id)[0]; @@ -27,9 +28,9 @@ export const getQuickActionText = note => { return text; }; -export const hasQuickActions = note => REGEX_QUICK_ACTIONS.test(note); +export const hasQuickActions = note => createQuickActionsRegex().test(note); -export const stripQuickActions = note => note.replace(REGEX_QUICK_ACTIONS, '').trim(); +export const stripQuickActions = note => note.replace(createQuickActionsRegex(), '').trim(); export const prepareDiffLines = diffLines => diffLines.map(line => ({ ...trimFirstCharOfLineContent(line) })); |