Переглянути джерело

[java] fix escaping backslashes on EReg.replace (closes #3430)

Aleksandr Kuzmenko 5 роки тому
батько
коміт
fcc06f2327
2 змінених файлів з 3 додано та 3 видалено
  1. 3 1
      std/java/_std/EReg.hx
  2. 0 2
      tests/unit/src/unitstd/EReg.unit.hx

+ 3 - 1
std/java/_std/EReg.hx

@@ -22,6 +22,8 @@
 
 import java.util.regex.*;
 
+using StringTools;
+
 @:coreApi class EReg {
 	private var pattern:String;
 	private var matcher:Matcher;
@@ -141,7 +143,7 @@ import java.util.regex.*;
 
 	public function replace(s:String, by:String):String {
 		matcher.reset(s);
-		by = by.split("$$").join("\\$");
+		by = by.replace("\\", "\\\\").replace("$$", "\\$");
 		return isGlobal ? matcher.replaceAll(by) : matcher.replaceFirst(by);
 	}
 

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

@@ -116,7 +116,5 @@ new EReg("^" + EReg.escape("\\ ^ $ * + ? . ( ) | { } [ ]") + "$", "").match("\\
 
 // #3430
 ~/(\d+)/g.replace("a1234b12","$1") == "a1234b12";
-#if !java
 ~/(\d+)/g.replace("a1234b12","\\$1") == "a\\1234b\\12";
-#end
 ~/(\d+)/g.replace("a1234b12","$$1") == "a$1b$1";