From d9041fa799611a2ea9a3bfd8064a5381a199cc63 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 15 Oct 2016 02:38:08 +0200 Subject: [PATCH] Fixed issue #207 - only match \Wword\W, add matching word in user location to confirm dialog (to make sure what word is matching). --- .../controllers/agent_ticket_create.coffee | 7 ++-- .../ticket_zoom/article_new.coffee | 7 ++-- .../javascripts/app/lib/app_post/utils.coffee | 9 ++--- public/assets/tests/html_utils.js | 40 ++++++++++++++++++- 4 files changed, 50 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee index 97315c2f1..67e011135 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee @@ -450,9 +450,10 @@ class App.TicketCreate extends App.Controller # save ticket, create article # check attachment if article['body'] - if App.Utils.checkAttachmentReference(article['body']) - if @$('.richtext .attachments .attachment').length < 1 - if !confirm( App.i18n.translateContent('You use attachment in text but no attachment is attached. Do you want to continue?') ) + if @$('.richtext .attachments .attachment').length < 1 + matchingWord = App.Utils.checkAttachmentReference(article['body']) + if matchingWord + if !confirm(App.i18n.translateContent('You use %s in text but no attachment is attached. Do you want to continue?', matchingWord)) return # disable form diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee index e87088d3b..0979968e6 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee @@ -374,9 +374,10 @@ class App.TicketZoomArticleNew extends App.Controller return false # check attachment - if params.body - if App.Utils.checkAttachmentReference(params.body) && attachmentCount < 1 - if !confirm( App.i18n.translateContent('You use attachment in text but no attachment is attached. Do you want to continue?') ) + if params.body && attachmentCount < 1 + matchingWord = App.Utils.checkAttachmentReference(params.body) + if matchingWord + if !confirm(App.i18n.translateContent('You use %s in text but no attachment is attached. Do you want to continue?', matchingWord)) return false if params.type is 'twitter status' diff --git a/app/assets/javascripts/app/lib/app_post/utils.coffee b/app/assets/javascripts/app/lib/app_post/utils.coffee index 747351799..e1bc97808 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.coffee @@ -594,18 +594,17 @@ class App.Utils # check if attachment is referenced in message @checkAttachmentReference: (message) -> return false if !message - return true if message.match(/attachment/i) matchwords = ['Attachment', 'attachment', 'Attached', 'attached', 'Enclosed', 'enclosed', 'Enclosure', 'enclosure'] for word in matchwords # en - attachmentTranslatedRegExp = new RegExp(word, 'i') - return true if message.match(attachmentTranslatedRegExp) + attachmentTranslatedRegExp = new RegExp("\\W#{word}\\W", 'i') + return word if message.match(attachmentTranslatedRegExp) # user locale attachmentTranslated = App.i18n.translateContent(word) - attachmentTranslatedRegExp = new RegExp(attachmentTranslated, 'i') - return true if message.match(attachmentTranslatedRegExp) + attachmentTranslatedRegExp = new RegExp("\\W#{attachmentTranslated}\\W", 'i') + return attachmentTranslated if message.match(attachmentTranslatedRegExp) false # human readable file size diff --git a/public/assets/tests/html_utils.js b/public/assets/tests/html_utils.js index 0a69024b2..1971bdb8a 100644 --- a/public/assets/tests/html_utils.js +++ b/public/assets/tests/html_utils.js @@ -38,7 +38,6 @@ test("textCleanup", function() { result = App.Utils.textCleanup(source) equal(result, should, source) - }); // text2html @@ -890,6 +889,44 @@ test("identify signature", function() { }); +// check attachment references +test("check replace tags", function() { + var message = 'some not existing' + var result = false + var verify = App.Utils.checkAttachmentReference(message) + equal(verify, result) + + message = 'some attachment for you' + result = 'Attachment' + verify = App.Utils.checkAttachmentReference(message) + equal(verify, result) + + message = 'your attachment.' + result = 'Attachment' + verify = App.Utils.checkAttachmentReference(message) + equal(verify, result) + + message = 'some otherattachment for you' + result = false + verify = App.Utils.checkAttachmentReference(message) + equal(verify, result) + + message = 'some attachmentother for you' + result = false + verify = App.Utils.checkAttachmentReference(message) + equal(verify, result) + + message = 'someattachment' + result = false + verify = App.Utils.checkAttachmentReference(message) + equal(verify, result) + + message = 'As enclosed you will find.' + result = 'Enclosed' + verify = App.Utils.checkAttachmentReference(message) + equal(verify, result) +}); + // replace tags test("check replace tags", function() { @@ -989,7 +1026,6 @@ test("check replace tags", function() { verify = App.Utils.replaceTags(message, data) equal(verify, result) - }); // check attibute validation