Browse Source

--- Merging r23866 into '.':
U packages/fcl-base/src/fpmimetypes.pp
--- Merging r24240 into '.':
U packages/fcl-base/src/inifiles.pp
--- Merging r24274 into '.':
U packages/fcl-base/src/gettext.pp
--- Merging r24321 into '.':
U packages/fcl-base/src/uriparser.pp

# revisions: 23866,24240,24274,24321
r23866 | michael | 2013-03-16 15:15:22 +0100 (Sat, 16 Mar 2013) | 1 line
Changed paths:
M /trunk/packages/fcl-base/src/fpmimetypes.pp

* Adapted patch from Mario Ray Mahardhika to fix empty mime type
r24240 | michael | 2013-04-14 17:34:00 +0200 (Sun, 14 Apr 2013) | 1 line
Changed paths:
M /trunk/packages/fcl-base/src/inifiles.pp

* Patch to avoid error when trying to create empty directory
r24274 | marco | 2013-04-20 14:01:42 +0200 (Sat, 20 Apr 2013) | 4 lines
Changed paths:
M /trunk/packages/fcl-base/src/gettext.pp

* Added some fileexists() near places where a stream was opened, but
relied on the exception mechanism to handle file not found.
Makes debugging easier.
r24321 | michael | 2013-04-25 20:15:25 +0200 (Thu, 25 Apr 2013) | 1 line
Changed paths:
M /trunk/packages/fcl-base/src/uriparser.pp

* Enhanced patch from Michalis Kamburelis (bug 24324)

git-svn-id: branches/fixes_2_6@24944 -

marco 12 years ago
parent
commit
b847b03f67

+ 13 - 8
packages/fcl-base/src/fpmimetypes.pp

@@ -147,14 +147,19 @@ Var
   I : integer;
   I : integer;
   E : String;
   E : String;
 begin
 begin
-  E:=LowerCase(AExt);
-  If (E[1]='.') then
-    Delete(E,1,1);
-  I:=FExtensions.FindIndexOf(E);
-  If (I<>-1) then
-    Result:=TMimeType(FExtensions.Items[I])
-  else
-    Result:=Nil;
+  if Length(AExt) = 0 then 
+    Result:=Nil
+  else 
+    begin
+    E:=LowerCase(AExt);
+    If (E[1]='.') then
+      Delete(E,1,1);
+    I:=FExtensions.FindIndexOf(E);
+    If (I<>-1) then
+      Result:=TMimeType(FExtensions.Items[I])
+    else
+      Result:=Nil;
+    end
 end;
 end;
 
 
 constructor TFPMimeTypes.Create(AOwner: TComponent);
 constructor TFPMimeTypes.Create(AOwner: TComponent);

+ 28 - 19
packages/fcl-base/src/gettext.pp

@@ -331,30 +331,39 @@ procedure TranslateResourceStrings(const AFilename: String);
 var
 var
   mo: TMOFile;
   mo: TMOFile;
   lang, FallbackLang: String;
   lang, FallbackLang: String;
+  fn: String;
 begin
 begin
   GetLanguageIDs(Lang, FallbackLang);
   GetLanguageIDs(Lang, FallbackLang);
-  try
-    mo := TMOFile.Create(Format(AFilename, [FallbackLang]));
-    try
-      TranslateResourceStrings(mo);
-    finally
-      mo.Free;
-    end;
-  except
-    on e: Exception do;
-  end;
+  fn:=Format(AFilename, [FallbackLang]);
 
 
+  if fileexists(fn) then
+    begin
+      try
+        mo := TMOFile.Create(fn);
+        try
+          TranslateResourceStrings(mo);
+        finally
+          mo.Free;
+        end;
+      except
+        on e: Exception do;
+      end;
+    end;
   lang := Copy(lang, 1, 5);
   lang := Copy(lang, 1, 5);
-  try
-    mo := TMOFile.Create(Format(AFilename, [lang]));
-    try
-      TranslateResourceStrings(mo);
-    finally
-      mo.Free;
+  fn:=Format(AFilename, [lang]);
+  if fileexists(fn) then
+    begin
+      try
+        mo := TMOFile.Create(Format(AFilename, [lang]));
+        try
+          TranslateResourceStrings(mo);
+        finally
+          mo.Free;
+        end;
+      except
+        on e: Exception do;
+      end;
     end;
     end;
-  except
-    on e: Exception do;
-  end;
 end;
 end;
 
 
 
 

+ 3 - 2
packages/fcl-base/src/inifiles.pp

@@ -951,8 +951,9 @@ begin
     if FFileName > '' then
     if FFileName > '' then
       begin
       begin
       D:=ExtractFilePath(FFileName);
       D:=ExtractFilePath(FFileName);
-      if not ForceDirectories(D) then
-        Raise EInoutError.CreateFmt(SErrCouldNotCreatePath,[D]);
+      If D <> '' Then
+        if not ForceDirectories(D) then
+          Raise EInoutError.CreateFmt(SErrCouldNotCreatePath,[D]);
       slLines.SaveToFile(FFileName);
       slLines.SaveToFile(FFileName);
       end
       end
     else if FStream <> nil then
     else if FStream <> nil then

+ 13 - 7
packages/fcl-base/src/uriparser.pp

@@ -47,7 +47,7 @@ function ResolveRelativeURI(const BaseUri, RelUri: UTF8String;
   out ResultUri: UTF8String): Boolean; overload;
   out ResultUri: UTF8String): Boolean; overload;
 
 
 function URIToFilename(const URI: string; out Filename: string): Boolean;
 function URIToFilename(const URI: string; out Filename: string): Boolean;
-function FilenameToURI(const Filename: string): string;
+function FilenameToURI(const Filename: string; Encode : Boolean = True): string;
 
 
 function IsAbsoluteURI(const UriReference: string): Boolean;
 function IsAbsoluteURI(const UriReference: string): Boolean;
 
 
@@ -321,7 +321,6 @@ begin
   end;
   end;
 end;
 end;
 
 
-// TODO: this probably must NOT percent-encode the result...
 function ResolveRelativeURI(const BaseUri, RelUri: UTF8String;
 function ResolveRelativeURI(const BaseUri, RelUri: UTF8String;
   out ResultUri: UTF8String): Boolean;
   out ResultUri: UTF8String): Boolean;
 var
 var
@@ -366,6 +365,8 @@ begin
       RemoveDotSegments(Path);
       RemoveDotSegments(Path);
     end;
     end;
   end; // with
   end; // with
+  
+  // EncodeUri percent-encodes the result, and that's good
   ResultUri := EncodeUri(Rel);
   ResultUri := EncodeUri(Rel);
 end;
 end;
 
 
@@ -412,10 +413,11 @@ begin
   end;
   end;
 end;
 end;
 
 
-function FilenameToURI(const Filename: string): string;
+function FilenameToURI(const Filename: string; Encode : Boolean = True): string;
 var
 var
   I: Integer;
   I: Integer;
   IsAbsFilename: Boolean;
   IsAbsFilename: Boolean;
+  FilenamePart: string;
 begin
 begin
   IsAbsFilename := ((Filename <> '') and (Filename[1] = PathDelim)) or
   IsAbsFilename := ((Filename <> '') and (Filename[1] = PathDelim)) or
     ((Length(Filename) > 2) and (Filename[1] in ['A'..'Z', 'a'..'z']) and (Filename[2] = ':'));
     ((Length(Filename) > 2) and (Filename[1] in ['A'..'Z', 'a'..'z']) and (Filename[2] = ':'));
@@ -429,17 +431,21 @@ begin
       Result := Result + '//';
       Result := Result + '//';
   end;
   end;
 
 
-  Result := Result + Filename;
+  FilenamePart := Filename;
   { unreachable code warning is ok here }
   { unreachable code warning is ok here }
   if PathDelim <> '/' then
   if PathDelim <> '/' then
   begin
   begin
-    I := Pos(PathDelim, Result);
+    I := Pos(PathDelim, FilenamePart);
     while I <> 0 do
     while I <> 0 do
     begin
     begin
-      Result[I] := '/';
-      I := Pos(PathDelim, Result);
+      FilenamePart[I] := '/';
+      I := Pos(PathDelim, FilenamePart);
     end;
     end;
   end;
   end;
+  if Encode then
+    FilenamePart := Escape(FilenamePart, ValidPathChars);
+
+  Result := Result + FilenamePart;
 end;
 end;