View Issue Details

IDProjectCategoryView StatusLast Update
0022953LazarusLazUtilspublic2012-09-24 22:33
ReporterTakeda MatsukiAssigned ToMaxim Ganetsky 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version1.1 (SVN)Product Build 
Target VersionFixed in Version1.1 (SVN) 
Summary0022953: [Patch] "Fileutil.ReadFileToString" failed to work if file Name/directories contains Unicode character
Description
Fileutil.ReadFileToString would failed to work if file name and/or the directory contains unicode Character. (e.g. C:\フルサポート\전체 지원\การสนับสนุนอย่างเต็มที่.txt)
If the file name and/or the directory not contains unicode character it would working fine.

I attach :
1. Project Test (Test ReadToString Prj.7z),
2. File Text Test (Text test.7z),
3. Patch for it (2012-09-22 - FileUtil.ReadFileToString unicode ready patch.patch)

After applying my patch, FileUtil.ReadFileToString would working fine with Unicode Character.

Regards,
Takeda.
TagsNo tags attached.
Fixed in Revision38816
LazTarget-
WidgetsetWin32/Win64
Attached Files
  • 2012-09-22 - FileUtil.ReadFileToString unicode ready patch.patch (771 bytes)
    Index: fileutil.inc
    ===================================================================
    --- fileutil.inc	(revision 38794)
    +++ fileutil.inc	(working copy)
    @@ -1543,15 +1543,15 @@
      ------------------------------------------------------------------------------}
     function ReadFileToString(const Filename: String): String;
     var
    -  fs: TFileStream;
    +  fs: TFileStreamUTF8;
     begin
       Result := '';
       try
    -    fs := TFileStream.Create(UTF8ToSys(Filename), fmOpenRead or fmShareDenyWrite);
    +    fs := TFileStreamUTF8.Create(Filename, fmOpenRead or fmShareDenyWrite);
         try
           Setlength(Result, fs.Size);
           if Result <> '' then
    -        fs.Read(Result[1], Length(Result));
    +        fs.Read(Result[1], UTF8Length(Result));
         finally
           fs.Free;
         end;
    
  • Test ReadToString Prj.7z (60,382 bytes)
  • Text test.7z (1,048 bytes)

Activities

2012-09-23 01:14

 

2012-09-22 - FileUtil.ReadFileToString unicode ready patch.patch (771 bytes)
Index: fileutil.inc
===================================================================
--- fileutil.inc	(revision 38794)
+++ fileutil.inc	(working copy)
@@ -1543,15 +1543,15 @@
  ------------------------------------------------------------------------------}
 function ReadFileToString(const Filename: String): String;
 var
-  fs: TFileStream;
+  fs: TFileStreamUTF8;
 begin
   Result := '';
   try
-    fs := TFileStream.Create(UTF8ToSys(Filename), fmOpenRead or fmShareDenyWrite);
+    fs := TFileStreamUTF8.Create(Filename, fmOpenRead or fmShareDenyWrite);
     try
       Setlength(Result, fs.Size);
       if Result <> '' then
-        fs.Read(Result[1], Length(Result));
+        fs.Read(Result[1], UTF8Length(Result));
     finally
       fs.Free;
     end;

2012-09-23 01:14

 

Test ReadToString Prj.7z (60,382 bytes)

2012-09-23 01:15

 

Text test.7z (1,048 bytes)

Maxim Ganetsky

2012-09-24 22:33

developer   ~0062603

Applied, thanks.

Please test and close if ok.

Issue History

Date Modified Username Field Change
2012-09-23 01:14 Takeda Matsuki New Issue
2012-09-23 01:14 Takeda Matsuki File Added: 2012-09-22 - FileUtil.ReadFileToString unicode ready patch.patch
2012-09-23 01:14 Takeda Matsuki Widgetset => Win32/Win64
2012-09-23 01:14 Takeda Matsuki File Added: Test ReadToString Prj.7z
2012-09-23 01:15 Takeda Matsuki File Added: Text test.7z
2012-09-24 22:33 Maxim Ganetsky Fixed in Revision => 38816
2012-09-24 22:33 Maxim Ganetsky LazTarget => -
2012-09-24 22:33 Maxim Ganetsky Status new => resolved
2012-09-24 22:33 Maxim Ganetsky Fixed in Version => 1.1 (SVN)
2012-09-24 22:33 Maxim Ganetsky Resolution open => fixed
2012-09-24 22:33 Maxim Ganetsky Assigned To => Maxim Ganetsky
2012-09-24 22:33 Maxim Ganetsky Note Added: 0062603