4 Commits 4d996eaab4 ... 1b7bd68eaa

Autor SHA1 Mensaje Fecha
  yjp 1b7bd68eaa 修改bug hace 4 días
  yjp 6ecf24e6ac Merge branch 'v1.8.0' hace 4 días
  yjp 486cc2522e 合并 hace 1 semana
  yjp c8a25fd90f 添加sql处理函数 hace 1 semana
Se han modificado 2 ficheros con 24 adiciones y 0 borrados
  1. 12 0
      framework/core/api/url_instruction.go
  2. 12 0
      test/url_instruction_test.go

+ 12 - 0
framework/core/api/url_instruction.go

@@ -18,8 +18,16 @@ type UrlInstruction interface {
 }
 
 func FormUrlInstruction(instructions ...UrlInstruction) string {
+	if instructions == nil || len(instructions) == 0 {
+		return ""
+	}
+
 	urlInstructions := make([]string, 0)
 	for _, instruction := range instructions {
+		if instruction == nil {
+			continue
+		}
+
 		urlInstruction, err := instruction.FormUrlInstruction()
 		if err != nil {
 			panic(err)
@@ -28,6 +36,10 @@ func FormUrlInstruction(instructions ...UrlInstruction) string {
 		urlInstructions = append(urlInstructions, urlInstruction)
 	}
 
+	if urlInstructions == nil || len(urlInstructions) == 0 {
+		return ""
+	}
+
 	return "${" + strings.Join(urlInstructions, " ") + "}$"
 }
 

+ 12 - 0
test/url_instruction_test.go

@@ -81,4 +81,16 @@ func TestFormUrlInstruction(t *testing.T) {
 	if formed != excepted {
 		t.Fatalf("生成错误 excepted: %s actual: %s\n", excepted, formed)
 	}
+
+	formed = api.FormUrlInstruction(nil)
+	excepted = ``
+	if formed != excepted {
+		t.Fatalf("生成错误 excepted: %s actual: %s\n", excepted, formed)
+	}
+
+	formed = api.FormUrlInstruction()
+	excepted = ``
+	if formed != excepted {
+		t.Fatalf("生成错误 excepted: %s actual: %s\n", excepted, formed)
+	}
 }