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:
parent
baf54aaf8d
commit
d9041fa799
4 changed files with 50 additions and 13 deletions
|
@ -450,9 +450,10 @@ class App.TicketCreate extends App.Controller
|
||||||
# save ticket, create article
|
# save ticket, create article
|
||||||
# check attachment
|
# check attachment
|
||||||
if article['body']
|
if article['body']
|
||||||
if App.Utils.checkAttachmentReference(article['body'])
|
|
||||||
if @$('.richtext .attachments .attachment').length < 1
|
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?') )
|
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
|
return
|
||||||
|
|
||||||
# disable form
|
# disable form
|
||||||
|
|
|
@ -374,9 +374,10 @@ class App.TicketZoomArticleNew extends App.Controller
|
||||||
return false
|
return false
|
||||||
|
|
||||||
# check attachment
|
# check attachment
|
||||||
if params.body
|
if params.body && attachmentCount < 1
|
||||||
if App.Utils.checkAttachmentReference(params.body) && attachmentCount < 1
|
matchingWord = App.Utils.checkAttachmentReference(params.body)
|
||||||
if !confirm( App.i18n.translateContent('You use attachment in text but no attachment is attached. Do you want to continue?') )
|
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
|
return false
|
||||||
|
|
||||||
if params.type is 'twitter status'
|
if params.type is 'twitter status'
|
||||||
|
|
|
@ -594,18 +594,17 @@ class App.Utils
|
||||||
# check if attachment is referenced in message
|
# check if attachment is referenced in message
|
||||||
@checkAttachmentReference: (message) ->
|
@checkAttachmentReference: (message) ->
|
||||||
return false if !message
|
return false if !message
|
||||||
return true if message.match(/attachment/i)
|
|
||||||
matchwords = ['Attachment', 'attachment', 'Attached', 'attached', 'Enclosed', 'enclosed', 'Enclosure', 'enclosure']
|
matchwords = ['Attachment', 'attachment', 'Attached', 'attached', 'Enclosed', 'enclosed', 'Enclosure', 'enclosure']
|
||||||
for word in matchwords
|
for word in matchwords
|
||||||
|
|
||||||
# en
|
# en
|
||||||
attachmentTranslatedRegExp = new RegExp(word, 'i')
|
attachmentTranslatedRegExp = new RegExp("\\W#{word}\\W", 'i')
|
||||||
return true if message.match(attachmentTranslatedRegExp)
|
return word if message.match(attachmentTranslatedRegExp)
|
||||||
|
|
||||||
# user locale
|
# user locale
|
||||||
attachmentTranslated = App.i18n.translateContent(word)
|
attachmentTranslated = App.i18n.translateContent(word)
|
||||||
attachmentTranslatedRegExp = new RegExp(attachmentTranslated, 'i')
|
attachmentTranslatedRegExp = new RegExp("\\W#{attachmentTranslated}\\W", 'i')
|
||||||
return true if message.match(attachmentTranslatedRegExp)
|
return attachmentTranslated if message.match(attachmentTranslatedRegExp)
|
||||||
false
|
false
|
||||||
|
|
||||||
# human readable file size
|
# human readable file size
|
||||||
|
|
|
@ -38,7 +38,6 @@ test("textCleanup", function() {
|
||||||
result = App.Utils.textCleanup(source)
|
result = App.Utils.textCleanup(source)
|
||||||
equal(result, should, source)
|
equal(result, should, source)
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// text2html
|
// 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
|
// replace tags
|
||||||
test("check replace tags", function() {
|
test("check replace tags", function() {
|
||||||
|
|
||||||
|
@ -989,7 +1026,6 @@ test("check replace tags", function() {
|
||||||
verify = App.Utils.replaceTags(message, data)
|
verify = App.Utils.replaceTags(message, data)
|
||||||
equal(verify, result)
|
equal(verify, result)
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// check attibute validation
|
// check attibute validation
|
||||||
|
|
Loading…
Reference in a new issue