Browse Source

[php] fix StringTools.endsWith() for the unicode second arg (fixes #8211)

Alexander Kuzmenko 6 years ago
parent
commit
8a64087230
2 changed files with 11 additions and 2 deletions
  1. 2 2
      std/php/_std/StringTools.hx
  2. 9 0
      tests/unit/src/unit/issues/Issue8211.hx

+ 2 - 2
std/php/_std/StringTools.hx

@@ -45,11 +45,11 @@ import php.*;
 	}
 
 	public static function startsWith( s : String, start : String ) : Bool {
-		return start == '' || Global.strpos(s, start) == 0;
+		return start == '' || Global.substr(s, 0, Global.strlen(start)) == start;
 	}
 
 	public static function endsWith( s : String, end : String ) : Bool {
-		return end == '' || Global.substr(s, -end.length) == end;
+		return end == '' || Global.substr(s, -Global.strlen(end)) == end;
 	}
 
 	public static function isSpace( s : String, pos : Int ) : Bool {

+ 9 - 0
tests/unit/src/unit/issues/Issue8211.hx

@@ -0,0 +1,9 @@
+package unit.issues;
+
+class Issue8211 extends unit.Test {
+	function test() {
+		t(StringTools.endsWith("abc", "bc"));
+		t(StringTools.endsWith("aňa", "ňa"));
+		t(StringTools.endsWith("\u{1F604}\u{1F619}", "\u{1F604}\u{1F619}"));
+	}
+}