maxiaoshan 3 ani în urmă
părinte
comite
676112d539
1 a modificat fișierele cu 15 adăugiri și 6 ștergeri
  1. 15 6
      src/spider/script.go

+ 15 - 6
src/spider/script.go

@@ -712,15 +712,24 @@ func (s *Script) LoadScript(code, script_file string, newstate bool) string {
 		if len(text) > 0 {
 			textRune := []rune(text)
 			textLen := len(textRune)
-			if end == -1 {
-				if start >= 1 { //正向截取到结尾
-					result = string(textRune[start-1:])
-				} else if start < 0 && textLen+start >= 0 { //反向截取后缀
-					result = string(textRune[textLen+start:])
+			if end < 0 {
+				if start > 0 { //正向截取到倒数第end位
+					result = string(textRune[start-1 : textLen+1+end])
+				} else if start < 0 { //反向截取 从倒数第start位截取到倒数第end位
+					result = string(textRune[textLen+start : textLen+1+end])
 				}
-			} else if start >= 1 && end <= textLen { //从第start个截取到第end个
+			} else if start > 0 && end >= start && end <= textLen { //从第start个截取到第end个
 				result = string(textRune[start-1 : end])
 			}
+			// if end == -1 {
+			// 	if start >= 1 { //正向截取到结尾
+			// 		result = string(textRune[start-1:])
+			// 	} else if start < 0 && textLen+start >= 0 { //反向截取后缀
+			// 		result = string(textRune[textLen+start:])
+			// 	}
+			// } else if start >= 1 && end <= textLen { //从第start个截取到第end个
+			// 	result = string(textRune[start-1 : end])
+			// }
 		}
 		S.Push(lua.LString(result))
 		return 1