Browse Source

added support for quotes in StringTools html escaping

Nicolas Cannasse 12 years ago
parent
commit
b9c44ada5b
5 changed files with 6 additions and 23 deletions
  1. 1 0
      doc/CHANGES.txt
  2. 1 1
      genneko.ml
  3. 3 3
      std/StringTools.hx
  4. 1 0
      tests/unit/Test.hx
  5. 0 19
      tests/unit/TestBasetypes.hx

+ 1 - 0
doc/CHANGES.txt

@@ -21,6 +21,7 @@
 	all : Haxe3 packages changes (see http://haxe.org/manual/haxe3)
 	all : Removed haxe.Int32, haxe.Firebug, haxe.TimerQueue
 	all : added -D key=value and #if (key >= value) operations
+	all : StringTools.htmlEscape/unescape nows handle "/" and '/'
 	
 2012-07-16: 2.10
 	java/cs : added two new targets (beta)

+ 1 - 1
genneko.ml

@@ -815,7 +815,7 @@ let build ctx types =
 	packs @ methods @ boot :: names @ inits @ vars
 
 let generate com =
-	let ctx = new_context com (if Common.defined com Define.Haxe3 || Common.defined com Define.NekoV2 then 2 else 1) false in
+	let ctx = new_context com (if Common.defined com Define.NekoV2 then 2 else 1) false in
 	let t = Common.timer "neko generation" in
 	let libs = (EBlock (generate_libs_init com.neko_libs) , { psource = "<header>"; pline = 1; }) in
 	let el = build ctx com.types in

+ 3 - 3
std/StringTools.hx

@@ -88,7 +88,7 @@ class StringTools {
 		Escape HTML special characters of the string.
 	**/
 	public static function htmlEscape( s : String ) : String {
-		return s.split("&").join("&amp;").split("<").join("&lt;").split(">").join("&gt;");
+		return s.split("&").join("&amp;").split("<").join("&lt;").split(">").join("&gt;").split('"').join("&quot;").split("'").join("&#039;");
 	}
 
 	/**
@@ -98,7 +98,7 @@ class StringTools {
 		#if php
 		return untyped __call__("htmlspecialchars_decode", s);
 		#else
-		return s.split("&gt;").join(">").split("&lt;").join("<").split("&amp;").join("&");
+		return s.split("&gt;").join(">").split("&lt;").join("<").split("&quot;").join('"').split("&#039;").join("'").split("&amp;").join("&");
 		#end
 	}
 
@@ -307,7 +307,7 @@ class StringTools {
 		return s.cca(index);
 		#end
 	}
-	
+
 	#if java
 	private static inline function _charAt(str:String, idx:Int):java.StdTypes.Char16 return untyped str._charAt(idx)
 	#end

+ 1 - 0
tests/unit/Test.hx

@@ -226,6 +226,7 @@ package unit;
 			new TestMeta(),
 			new TestType(),
 			new TestOrder(),
+			new TestStringTools(),
 			#if cs
 			new TestCSharp(),
 			#end

+ 0 - 19
tests/unit/TestBasetypes.hx

@@ -220,25 +220,6 @@ class TestBasetypes extends Test {
 		eq( Std.parseFloat("5.3 1"), 5.3 );
 	}
 
-	function testStringTools() {
-		eq( StringTools.hex(0xABCDEF,7), "0ABCDEF" );
-		eq( StringTools.hex(-1,8), "FFFFFFFF" );
-		eq( StringTools.hex(-481400000,8), "E34E6B40" );
-	}
-	
-	function testCCA() {
-		var str = "abc";
-		eq( StringTools.fastCodeAt(str, 0), "a".code );
-		eq( StringTools.fastCodeAt(str, 1), "b".code );
-		eq( StringTools.fastCodeAt(str, 2), "c".code );
-		eq(StringTools.fastCodeAt(String.fromCharCode(128), 0), 128);
-		eq(StringTools.fastCodeAt(String.fromCharCode(255), 0), 255);
-		f( StringTools.isEOF(StringTools.fastCodeAt(str, 2)) );
-		t( StringTools.isEOF(StringTools.fastCodeAt(str, 3)) );
-		
-		t( StringTools.isEOF(StringTools.fastCodeAt("", 0)) );
-	}
-	
 	function testHash() {
 		var h = new Hash<Null<Int>>();
 		h.set("x", -1);