Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] ocamlnet doesn't correspond to pcre from 04/29 change onward
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Takayuki Kazama <kazaan@h...>
Subject: [Caml-list] ocamlnet doesn't correspond to pcre from 04/29 change onward
Hello, all.

I've found the code in ocamlnet-0.98 should be fix to correspond to 
-new- Pcre.get_substring.

Since 2004-04-29, the function "get_substring" does not return null string
even if accessed substring was not captured. It raises "Not_found".
(Check pcre-ocaml's changelog)

So now, it seems that Netencoding.Html.decode don't work right way.
I've checked this at ...
	Debian GNU/Linux(sid)	ocaml			3.08.1-1
				libpcre-ocaml		5.08.1-2
				libocamlnet-ocaml	0.98-2.1
and
	M$ Windows2000		Ocaml-MinGW-Maxi Distibution.
(Note: netstring/Makefile was changed for ocaml/mingw build
because of no ocamlmklib in ocaml/mingw)

Problem is like bellow.

shell$ ocaml
# #use "topfind";;
# #require "netstring";;
# Netencoding.Html.encode_from_latin1 "(a<b)&(c>d)";;
- : string = "(a&lt;b)&amp;(c&gt;d)"
	(* We could `encode' with propriety. But... *)
# Netencoding.Html.decode_to_latin1 "(a&lt;b)&amp;(c&gt;d)"
Exception: Not_found.
	(* Oops. So now try by the number-encoding -- like &#60 -- *)
# Netencoding.Html.decode_to_latin1 "(a&#60;b)&#38;(c&#62;d)"
- : string = "(a<b)&(c>d)"
	(* Good. So we cannot decode "&[a-zA-Z];" encoding only *)

To fix this problem, change netencoding.ml like bellow (diff -c)
*** netencoding.ml		Thu Oct 14 20:54:56 2004
--- netencoding.ml.org		Sat Sep  4 22:20:36 2004
***************
*** 1536,1547 ****
	 (* TODO: avoid String.sub *)
	 let occurence = occurences.(k) in
	 let replacement =
!	   try
!	     let n = int_of_string (Pcre.get_substring occurence 2) in
!	       makechar n
!	   with Not_found ->
!	     let name = Pcre.get_substring occurence 3 in
!	       lookup_entity name
	 in
	 Buffer.add_string buf replacement;
	 n := n1;
--- 1536,1551 ----
	 (* TODO: avoid String.sub *)
	 let occurence = occurences.(k) in
	 let replacement =
!	   let num = Pcre.get_substring occurence 2 in   (* or " *)
!	   if num <> "" then begin
!	     let n = int_of_string num in
!	     makechar n
!	   end
!	   else begin
!	     let name = Pcre.get_substring occurence 3 in  (* or "" *)
!	     assert(name <> "");
!	     lookup_entity name
!	   end
	 in
	 Buffer.add_string buf replacement;
	 n := n1;

And I suggest that change the functions "matched_string" and "matched_group".
Because Pcre.get_substring will raise Not_found now 8)

regards.

---
Takayuki Kazama

mail : kazaan@hh.iij4u.or.jp
blog : http://kazaan.no-ip.com/~kazaan/ (SORRY JAPANESE ONLY)

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners