Skip to content

Commit 50d579b

Browse files
committed
Fix URL decoding.
Remove the translation from plus sign (+) to space in URL. This prevents downloading any file having a + in its name. This translation must be done only for parameters (after ? in the URL). Fixes U326-027.
1 parent 8262ef4 commit 50d579b

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

src/core/aws-url-set.adb

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Ada Web Server --
33
-- --
4-
-- Copyright (C) 2007-2019, AdaCore --
4+
-- Copyright (C) 2007-2021, AdaCore --
55
-- --
66
-- This library is free software; you can redistribute it and/or modify --
77
-- it under terms of the GNU General Public License as published by the --
@@ -206,7 +206,30 @@ package body AWS.URL.Set is
206206
---------------------
207207

208208
procedure Parse_Path_File (Start : Positive) is
209-
PF : constant String := Decode (URL (Start .. URL'Last));
209+
210+
function Parameters_Start return Positive;
211+
-- Get the start of the parameters if any. We need that as only
212+
-- the URL parameters must decode plus characters as spaces.
213+
214+
----------------------
215+
-- Parameters_Start --
216+
----------------------
217+
218+
function Parameters_Start return Positive is
219+
begin
220+
for K in Start .. URL'Last loop
221+
if URL (K) = '?' then
222+
return K;
223+
end if;
224+
end loop;
225+
226+
return URL'Last;
227+
end Parameters_Start;
228+
229+
P : constant Positive := Parameters_Start;
230+
PF : constant String :=
231+
Decode (URL (Start .. P), In_Params => False)
232+
& Decode (URL (P + 1 .. URL'Last), In_Params => True);
210233
I3 : constant Natural :=
211234
Strings.Fixed.Index (PF, "/", Strings.Backward);
212235
begin

src/core/aws-url.adb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Ada Web Server --
33
-- --
4-
-- Copyright (C) 2000-2017, AdaCore --
4+
-- Copyright (C) 2000-2021, AdaCore --
55
-- --
66
-- This library is free software; you can redistribute it and/or modify --
77
-- it under terms of the GNU General Public License as published by the --
@@ -103,7 +103,7 @@ package body AWS.URL is
103103
-- Decode --
104104
------------
105105

106-
function Decode (Str : String) return String is
106+
function Decode (Str : String; In_Params : Boolean) return String is
107107
Res : String (1 .. Str'Length);
108108
K : Natural := 0;
109109
I : Positive := Str'First;
@@ -123,7 +123,7 @@ package body AWS.URL is
123123
Res (K) := Character'Val (Utils.Hex_Value (Str (I + 1 .. I + 2)));
124124
I := I + 2;
125125

126-
elsif Str (I) = '+' then
126+
elsif In_Params and then Str (I) = '+' then
127127
-- A plus is used for spaces in forms value for example
128128
Res (K) := ' ';
129129

@@ -138,6 +138,11 @@ package body AWS.URL is
138138
return Res (1 .. K);
139139
end Decode;
140140

141+
function Decode (Str : String) return String is
142+
begin
143+
return Decode (Str, In_Params => True);
144+
end Decode;
145+
141146
function Decode (Str : Unbounded_String) return Unbounded_String is
142147
use Characters.Handling;
143148
Res : Unbounded_String;

src/core/aws-url.ads

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Ada Web Server --
33
-- --
4-
-- Copyright (C) 2000-2017, AdaCore --
4+
-- Copyright (C) 2000-2021, AdaCore --
55
-- --
66
-- This library is free software; you can redistribute it and/or modify --
77
-- it under terms of the GNU General Public License as published by the --
@@ -248,4 +248,8 @@ private
248248
Parameters_Encoding_Set
249249
or Strings.Maps.To_Set (";/:$,""{}|\^[]`'");
250250

251+
function Decode (Str : String; In_Params : Boolean) return String;
252+
-- Decode URL Str. In_Params is set to True when decoding the
253+
-- parameters URL's fragment.
254+
251255
end AWS.URL;

0 commit comments

Comments
 (0)