changeset 106:6de4932d993b extractapp

bug fixed: prevent page halted bcuz the null tagging result from Regex
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 08 Aug 2016 17:47:19 +0200
parents 4eb62953af99
children 7f2c5d542616
files js/taggingtext.js
diffstat 1 files changed, 26 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/js/taggingtext.js	Fri Aug 05 15:49:55 2016 +0200
+++ b/js/taggingtext.js	Mon Aug 08 17:47:19 2016 +0200
@@ -987,7 +987,11 @@
     var el = document.getElementById("editable-area");
     var str="" + el.innerHTML;
     
-    if ( startPage == "" ) {
+    // if there's no match || the it's a null object..
+    if (str.match(new RegExp(replaceSmartRegexString, "g")) == null) {
+        alert( "Tagged 0 entity!" );
+
+    } else if ( startPage == "" ) {
         alert( "Tagged "+str.match(new RegExp(replaceSmartRegexString, "g")).length+" entities!" );
         el.innerHTML = str.replace(new RegExp(replaceSmartRegexString, "g"), replaceSmartReplaceString);
     } else {
@@ -1040,8 +1044,13 @@
     var el = document.getElementById("editable-area");
     var str="" + el.innerHTML;
     
-    if ( startPage == "" ) {
+    // if there's no match || the it's a null object..
+    if (str.match(new RegExp(replaceSmartRegexString, "g")) == null) {
+        alert( "Tagged 0 entity!" );
+
+    } else if ( startPage == "" ) {
         alert( "Tagged "+str.match(new RegExp(replaceSmartRegexString, "g")).length+" entities!" );
+
         el.innerHTML = str.replace(new RegExp(replaceSmartRegexString, "g"), replaceSmartReplaceString);
     } else {
         var regexText="【<a([^<>]*?)>"+startPage+"</a>】(.*?)【<a([^<>]*?)>"+endPage+"</a>】";
@@ -1087,7 +1096,11 @@
     var el = document.getElementById("editable-area");
     var str="" + el.innerHTML;
     
-    if ( startPage == "" ) {
+    // if there's no match || the it's a null object..
+    if (str.match(new RegExp(replaceSmartRegexString, "g")) == null) {
+        alert( "Tagged 0 entity!" );
+
+    } else if ( startPage == "" ) {
         alert( "Tagged "+str.match(new RegExp(replaceSmartRegexString, "g")).length+" entities!" );
         el.innerHTML = str.replace(new RegExp(replaceSmartRegexString, "g"), replaceSmartReplaceString);
     } else {
@@ -1134,7 +1147,17 @@
 
     var name=prompt("Please enter this Regex name", RegexLoadedName+"_"+today);
 
+
+
     if (name!=null && name != ''){
+        
+        // the name not allowed to contain " ", "(", ")" 
+        if (name.indexOf(' ') >= 0 || name.indexOf('(') >= 0 || name.indexOf(')') >= 0) {
+
+            alert("Save Regex Failed.\nPlease don't use space or '(' or ')' in the name. Consider to use '-' or '_' instead. ");
+            return;
+        } 
+
         $.ajax({
             type : 'POST',
             url : './TaggingText',