Skip to content

Commit 2fb9127

Browse files
TurboGitogorodnik
authored andcommitted
Fix handling of XML text parsing.
The elements with types xsd:token, xsd:normalizedString and xsd:Any_URI where not properly supporting text value split over multiple XML text nodes. TN eng/toolchain/aws#100
1 parent 582e7b5 commit 2fb9127

File tree

3 files changed

+40
-56
lines changed

3 files changed

+40
-56
lines changed

src/soap/soap-message-xml.adb

Lines changed: 11 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -865,22 +865,9 @@ package body SOAP.Message.XML is
865865
function Parse_Any_URI
866866
(Name : String;
867867
Type_Name : String;
868-
N : DOM.Core.Node) return Types.Object'Class
869-
is
870-
use type DOM.Core.Node_Types;
871-
872-
L : constant DOM.Core.Node_List := Child_Nodes (N);
873-
S : Unbounded_String;
874-
P : DOM.Core.Node;
868+
N : DOM.Core.Node) return Types.Object'Class is
875869
begin
876-
for I in 0 .. Length (L) - 1 loop
877-
P := Item (L, I);
878-
if P.Node_Type = DOM.Core.Text_Node then
879-
Append (S, Node_Value (P));
880-
end if;
881-
end loop;
882-
883-
return Types.AnyURI (To_String (S), Name, Type_Name);
870+
return Types.AnyURI (SOAP.XML.Text_Node_Value (N), Name, Type_Name);
884871
end Parse_Any_URI;
885872

886873
-----------------
@@ -1406,11 +1393,9 @@ package body SOAP.Message.XML is
14061393
function Parse_Normalized_String
14071394
(Name : String;
14081395
Type_Name : String;
1409-
N : DOM.Core.Node) return Types.Object'Class
1410-
is
1411-
Value : constant DOM.Core.Node := First_Child (N);
1396+
N : DOM.Core.Node) return Types.Object'Class is
14121397
begin
1413-
return Types.NS (Node_Value (Value), Name, Type_Name);
1398+
return Types.NS (SOAP.XML.Text_Node_Value (N), Name, Type_Name);
14141399
end Parse_Normalized_String;
14151400

14161401
-----------------
@@ -1862,22 +1847,10 @@ package body SOAP.Message.XML is
18621847
function Parse_String
18631848
(Name : String;
18641849
Type_Name : String;
1865-
N : DOM.Core.Node) return Types.Object'Class
1866-
is
1867-
use type DOM.Core.Node_Types;
1868-
1869-
L : constant DOM.Core.Node_List := Child_Nodes (N);
1870-
S : Unbounded_String;
1871-
P : DOM.Core.Node;
1850+
N : DOM.Core.Node) return Types.Object'Class is
18721851
begin
1873-
for I in 0 .. Length (L) - 1 loop
1874-
P := Item (L, I);
1875-
if P.Node_Type = DOM.Core.Text_Node then
1876-
Append (S, Node_Value (P));
1877-
end if;
1878-
end loop;
1879-
1880-
return Types.XSD_String'(Types.S (S, Name, Type_Name));
1852+
return Types.XSD_String'
1853+
(Types.S (SOAP.XML.Text_Node_Value (N), Name, Type_Name));
18811854
end Parse_String;
18821855

18831856
----------------
@@ -1917,12 +1890,10 @@ package body SOAP.Message.XML is
19171890
function Parse_Token
19181891
(Name : String;
19191892
Type_Name : String;
1920-
N : DOM.Core.Node) return Types.Object'Class
1921-
is
1922-
Value : constant DOM.Core.Node := First_Child (N);
1893+
N : DOM.Core.Node) return Types.Object'Class is
19231894
begin
19241895
return Types.XSD_Token'
1925-
(Types.T (Node_Value (Value), Name, Type_Name));
1896+
(Types.T (SOAP.XML.Text_Node_Value (N), Name, Type_Name));
19261897
end Parse_Token;
19271898

19281899
-------------------------
@@ -1991,23 +1962,9 @@ package body SOAP.Message.XML is
19911962

19921963
function Parse_Untyped
19931964
(Name : String;
1994-
N : DOM.Core.Node) return Types.Object'Class
1995-
is
1996-
use type DOM.Core.Node_Types;
1997-
1998-
L : constant DOM.Core.Node_List := Child_Nodes (N);
1999-
S : Unbounded_String;
2000-
P : DOM.Core.Node;
1965+
N : DOM.Core.Node) return Types.Object'Class is
20011966
begin
2002-
for I in 0 .. Length (L) - 1 loop
2003-
P := Item (L, I);
2004-
2005-
if P.Node_Type = DOM.Core.Text_Node then
2006-
Append (S, Node_Value (P));
2007-
end if;
2008-
end loop;
2009-
2010-
return Types.Untyped.S (S, Name);
1967+
return Types.Untyped.S (SOAP.XML.Text_Node_Value (N), Name);
20111968
end Parse_Untyped;
20121969

20131970
-------------------

src/soap/soap-xml.adb

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Ada Web Server --
33
-- --
4-
-- Copyright (C) 2003-2024, AdaCore --
4+
-- Copyright (C) 2003-2025, 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 --
@@ -28,6 +28,7 @@
2828
------------------------------------------------------------------------------
2929

3030
with Ada.Characters.Handling;
31+
with Ada.Strings.Unbounded;
3132

3233
with DOM.Core.Nodes;
3334

@@ -153,4 +154,26 @@ package body SOAP.XML is
153154
return M;
154155
end Next_Sibling;
155156

157+
---------------------
158+
-- Text_Node_Value --
159+
---------------------
160+
161+
function Text_Node_Value (N : DOM.Core.Node) return String is
162+
use Ada.Strings.Unbounded;
163+
use type DOM.Core.Node_Types;
164+
165+
L : constant DOM.Core.Node_List := DOM.Core.Nodes.Child_Nodes (N);
166+
S : Unbounded_String;
167+
P : DOM.Core.Node;
168+
begin
169+
for I in 0 .. DOM.Core.Nodes.Length (L) - 1 loop
170+
P := DOM.Core.Nodes.Item (L, I);
171+
if P.Node_Type = DOM.Core.Text_Node then
172+
Append (S, DOM.Core.Nodes.Node_Value (P));
173+
end if;
174+
end loop;
175+
176+
return To_String (S);
177+
end Text_Node_Value;
178+
156179
end SOAP.XML;

src/soap/soap-xml.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) 2003-2024, AdaCore --
4+
-- Copyright (C) 2003-2025, 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 --
@@ -60,4 +60,8 @@ package SOAP.XML is
6060
-- Returns the next sibling, skip #text nodes. Return null if there is no
6161
-- more sibbling.
6262

63+
function Text_Node_Value (N : DOM.Core.Node) return String;
64+
-- Returns the node value as a string. This ensure that a split string in
65+
-- multiple text nodes is fully returned.
66+
6367
end SOAP.XML;

0 commit comments

Comments
 (0)