Browse Source

php : fixed Issue 444
dce : fixed Issue 385

Franco Ponticelli 14 years ago
parent
commit
89a11529ba
2 changed files with 47 additions and 7 deletions
  1. 14 3
      std/php/_std/Xml.hx
  2. 33 4
      typeload.ml

+ 14 - 3
std/php/_std/Xml.hx

@@ -60,9 +60,20 @@ enum XmlType {
 		build = build.getParent();
 	}
 
+	private static function __decodeattr(value : String) : String
+	{
+		return untyped __call__("str_replace", "'", ''', __call__("htmlspecialchars", value, __php__('ENT_COMPAT'), 'UTF-8'));
+	}
+	
+	private static function __decodeent(value : String) : String
+	{
+		return untyped __call__("str_replace", "'", ''', __call__("htmlentities", value, __php__('ENT_COMPAT'), 'UTF-8'));
+	}
+	
 	private static function __character_data_handler(parser : Dynamic, data : String) : Void {
-		if((untyped __call__("strlen", data) == 1 && __call__("htmlentities", data) != data) || untyped __call__("htmlentities", data) == data) {
-			build.addChild(createPCData(untyped __call__("htmlentities", data)));
+		var d = __decodeent(data);
+		if((untyped __call__("strlen", data) == 1 && d != data) || d == data) {
+			build.addChild(createPCData(d));
 		} else
 			build.addChild(createCData(data));
 	}
@@ -202,7 +213,7 @@ enum XmlType {
 	public function set( att : String, value : String ) : Void {
 		if( nodeType != Xml.Element )
 			throw "bad nodeType";
-		_attributes.set( att, untyped __call__("str_replace", "'", ''', __call__("htmlspecialchars", value, __php__('ENT_COMPAT'), 'UTF-8')));
+		_attributes.set( att, __decodeattr(value) );
 	}
 
 	public function remove( att : String ) : Void{

+ 33 - 4
typeload.ml

@@ -781,8 +781,35 @@ let init_class ctx c p herits fields =
 		| Php -> [["php"], "Boot"]
 		| Cpp -> [["cpp"], "Boot"]
 		| _ -> [] in
-	let must_keep_class = (List.exists (fun p -> p = c.cl_path) (must_keep_types ctx.com.platform)) in
-	let keep f stat = core_api || (is_main f.cff_name) || c.cl_extern || must_keep_class || has_meta ":keep" c.cl_meta || has_meta ":keep" f.cff_meta || (stat && f.cff_name = "__init__") in
+	let must_keep_class =
+		List.exists (fun p -> p = c.cl_path) (must_keep_types ctx.com.platform)
+		|| c.cl_extern
+		|| has_meta ":keep" c.cl_meta 
+	in
+	let keep f stat =
+		   core_api 
+		|| (is_main f.cff_name)
+		|| must_keep_class 
+		|| has_meta ":keep" f.cff_meta 
+		|| (stat && f.cff_name = "__init__") 
+		|| (not stat 
+			&& f.cff_name = "resolve"
+			&& (match c.cl_dynamic with
+			| Some _ -> true
+			| None -> false
+			);
+		)
+	in
+	let rec setkeeper c =
+		match c.cl_super with
+		| Some (s,_) -> 
+			s.cl_meta <- if has_meta ":keep" s.cl_meta then s.cl_meta else begin
+				if ctx.com.verbose then print_endline ("Marking class " ^ (s_type_path s.cl_path) ^ " with :keep");
+				(":keep", [], p) :: s.cl_meta
+			end;
+			setkeeper s
+		| _ -> ()
+	in
 	let remove_by_cfname item lst = List.filter (fun i -> item <> i.cf_name) lst in
 	let remove_field cf stat =
 		if stat then begin
@@ -799,13 +826,15 @@ let init_class ctx c p herits fields =
 		| None ->
 			if ctx.com.verbose then print_endline ("Remove method " ^ (s_type_path c.cl_path) ^ "." ^ cf.cf_name);
 			remove_field cf stat
-		| _ -> ())
+		| _ -> 
+			setkeeper c;
+			())
 	in
 	let remove_var_if_unreferenced cf stat = (fun () ->
 		if not (has_meta ":?keep" cf.cf_meta) then begin
 			if ctx.com.verbose then print_endline ("Remove var " ^ (s_type_path c.cl_path) ^ "." ^ cf.cf_name);
 			remove_field cf stat
-		end)
+		end else setkeeper c)
 	in
 
 	(* ----------------------- COMPLETION ----------------------------- *)