From 98cb178fe80be7ee560c16e02dc31bf3df7700c8 Mon Sep 17 00:00:00 2001 From: Rory Byrne Date: Sat, 16 Jan 2010 11:18:39 +0000 Subject: Fix re:replace/4 to handle binary unicode output when nothing replaced A bug with re:replace/4 causes an exception when: (a) it's given a unicode charlist as input; (b) it's set to {return,binary}; and (c) it finds nothing to replace. The problem is: when re:replace/4 does not find anything to replace in its Subject input, it calls iolist_to_binary on this data. This fails if the original input is a charlist with non-ascii codepoints. --- lib/stdlib/src/re.erl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/stdlib/src') diff --git a/lib/stdlib/src/re.erl b/lib/stdlib/src/re.erl index 5417ac02e5..f934fdcba1 100644 --- a/lib/stdlib/src/re.erl +++ b/lib/stdlib/src/re.erl @@ -237,7 +237,12 @@ replace(Subject,RE,Replacement,Options) -> iodata -> IoList; binary -> - iolist_to_binary(IoList); + case Unicode of + false -> + iolist_to_binary(IoList); + true -> + unicode:characters_to_binary(IoList,unicode) + end; list -> case Unicode of false -> -- cgit v1.2.3