Fixed issue #207 - only match \Wword\W, add matching word in user location to confirm dialog (to make sure what word is matching).

This commit is contained in:
Martin Edenhofer 2016-10-15 02:38:08 +02:00
parent baf54aaf8d
commit d9041fa799
4 changed files with 50 additions and 13 deletions

View file

@ -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

View file

@ -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'

View file

@ -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

View file

@ -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