You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ju...@apache.org on 2019/11/09 01:44:04 UTC

[incubator-apisix-dashboard] branch master updated: fix:add regexp for uris and host filter when create route (#70)

This is an automated email from the ASF dual-hosted git repository.

juzhiyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 5fc1cec  fix:add regexp for uris and host filter when create route (#70)
5fc1cec is described below

commit 5fc1cecba832cff826de21514f36772ef0e9b37d
Author: Lien <li...@users.noreply.github.com>
AuthorDate: Sat Nov 9 09:43:55 2019 +0800

    fix:add regexp for uris and host filter when create route (#70)
    
    * add regexp for uris and host filter
    
    * fix error notice
    
    * Update edit.vue
---
 src/views/schema/routes/edit.vue | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/views/schema/routes/edit.vue b/src/views/schema/routes/edit.vue
index 98cabd1..1f82989 100644
--- a/src/views/schema/routes/edit.vue
+++ b/src/views/schema/routes/edit.vue
@@ -46,6 +46,7 @@
           filterable
           multiple
           default-first-option
+          @change="filterUriOptions"
         >
           <el-option
             v-for="item in ExistedUris"
@@ -67,6 +68,7 @@
           filterable
           allow-create
           default-first-option
+          @change="filterHostsOptions"
         >
           <el-option
             v-for="item in ExistedHosts"
@@ -248,7 +250,7 @@ export default class extends Vue {
   private ExistedHosts = [{ }]
 
   private rules = {
-    uri: {
+    uris: {
       required: true
     }
   }
@@ -293,6 +295,35 @@ export default class extends Vue {
     }
   }
 
+  filterDataWithRegex(val: any, regex: any) {
+    if (val.length > 0) {
+      const newArr:string[] = []
+      val.filter(function(item: any) {
+        if (typeof item === 'string') {
+          item = item.replace(/\s+/g, '')
+          if (regex.test(item)) {
+            newArr.push(item)
+          }
+        }
+      })
+      newArr.map(function(item: any, index: number) {
+        val[index] = item
+      })
+      if (val.length > newArr.length) {
+        val.splice(newArr.length, val.length)
+      }
+    }
+  }
+
+  private filterUriOptions(val: any) {
+    this.filterDataWithRegex(val, new RegExp('^([\\*\\./0-9a-zA-Z-_~@\\?\\!#$\\(\\)]+)$'))
+  }
+
+  private filterHostsOptions(val: any) {
+    let regexpFilter = new RegExp('^(([0-9a-zA-Z-]+|\\*)\\.)?([0-9a-zA-Z-]+\\.)+([a-zA-Z]{2,12})$')
+    this.filterDataWithRegex(val, regexpFilter)
+  }
+
   private async getData() {
     const { id } = this.$route.params
     const {