Преглед изворни кода

fix String.substr for python (#7383)

frabbit пре 7 година
родитељ
комит
d761d6bd08
2 измењених фајлова са 4 додато и 2 уклоњено
  1. 4 0
      std/python/internal/StringImpl.hx
  2. 0 2
      tests/unit/src/unitstd/Unicode.unit.hx

+ 4 - 0
std/python/internal/StringImpl.hx

@@ -114,6 +114,10 @@ class StringImpl {
 			return Syntax.arrayAccessWithTrailingColon(s, startIndex);
 		} else {
 			if (len == 0) return "";
+			if (startIndex < 0) {
+				startIndex = s.length + startIndex;
+				if (startIndex < 0) startIndex = 0;
+			}
 			return Syntax.arrayAccess(s, startIndex, startIndex+len);
 		}
 

+ 0 - 2
tests/unit/src/unitstd/Unicode.unit.hx

@@ -157,9 +157,7 @@ var s4 = s.substr(-1, 1);
 s1 == "e";
 s2 == "e";
 s3 == "e";
-#if !python
 s4 == "e";
-#end
 #if eval
 // We currently don't asciify anything we extract from UCS2 strings... not sure if this would
 // be worth it or not.