Skip to content

Commit 4b004a7

Browse files
authored
Align deserialization of restricted strings with standard strings (#1413)
1 parent 66c6d6a commit 4b004a7

File tree

6 files changed

+124
-1
lines changed

6 files changed

+124
-1
lines changed

src/wsdl/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,12 @@ export class WSDL {
367367
const topSchema = top.schema;
368368
const name = splitQName(nsName).name;
369369

370-
if (typeof cur.schema === 'string' && (cur.schema === 'string' || cur.schema.split(':')[1] === 'string')) {
370+
/**
371+
* When parsing a string element, we need to correctly transform `<tag></tag>`
372+
* to an empty string.
373+
*/
374+
const isStringElement = typeof cur.schema === 'string' && splitQName(cur.schema).name === 'string';
375+
if (isStringElement) {
371376
if (typeof obj === 'object' && Object.keys(obj).length === 0) {
372377
obj = cur.object = this.options.preserveWhitespace ? cur.text || '' : '';
373378
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://www.Dummy.com">
3+
<soap:Body>
4+
<DummyRequest xmlns="http://www.Dummy.com"></DummyRequest>
5+
</soap:Body>
6+
</soap:Envelope>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"foo": {
3+
"string_simple": "",
4+
"string_pattern": "",
5+
"string_simple_list": [""],
6+
"string_pattern_list": [""]
7+
}
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://www.Dummy.com">
3+
<soap:Body>
4+
<tns:DummyResponse>
5+
<tns:foo>
6+
<tns:string_simple></tns:string_simple>
7+
<tns:string_pattern></tns:string_pattern>
8+
<tns:string_simple_list></tns:string_simple_list>
9+
<tns:string_pattern_list></tns:string_pattern_list>
10+
</tns:foo>
11+
</tns:DummyResponse>
12+
</soap:Body>
13+
</soap:Envelope>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
3+
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
4+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
5+
xmlns:tns="http://www.Dummy.com"
6+
targetNamespace="http://www.Dummy.com">
7+
8+
<wsdl:types>
9+
<xs:schema targetNamespace="http://www.Dummy.com" elementFormDefault="qualified">
10+
<xs:complexType name="ComplexType" abstract="false">
11+
<xs:sequence>
12+
<xs:element name="string_simple" minOccurs="1" maxOccurs="1">
13+
<xs:simpleType>
14+
<xs:restriction base="xs:string">
15+
</xs:restriction>
16+
</xs:simpleType>
17+
</xs:element>
18+
<xs:element name="string_pattern" minOccurs="1" maxOccurs="1">
19+
<xs:simpleType>
20+
<xs:restriction base="xs:string">
21+
<xs:pattern value="[a-zA-Z0-9_ \-\+/\\\|\*=&lt;&gt;,.;:?!'`&quot;~@#$%^&amp;\(\)\[\]\{\}\r\n]{0,255}"/>
22+
</xs:restriction>
23+
</xs:simpleType>
24+
</xs:element>
25+
<xs:element name="string_simple_list" minOccurs="0" maxOccurs="25">
26+
<xs:simpleType>
27+
<xs:restriction base="xs:string">
28+
</xs:restriction>
29+
</xs:simpleType>
30+
</xs:element>
31+
<xs:element name="string_pattern_list" minOccurs="0" maxOccurs="25">
32+
<xs:simpleType>
33+
<xs:restriction base="xs:string">
34+
<xs:pattern value="[a-zA-Z0-9_ \-\+/\\\|\*=&lt;&gt;,.;:?!'`&quot;~@#$%^&amp;\(\)\[\]\{\}\r\n]{0,255}"/>
35+
</xs:restriction>
36+
</xs:simpleType>
37+
</xs:element>
38+
</xs:sequence>
39+
</xs:complexType>
40+
41+
<xs:element name="DummyRequest">
42+
<xs:complexType>
43+
<xs:sequence/>
44+
</xs:complexType>
45+
</xs:element>
46+
47+
<xs:element name="DummyResponse">
48+
<xs:complexType>
49+
<xs:sequence>
50+
<xs:element name="foo" type="tns:ComplexType"/>
51+
</xs:sequence>
52+
</xs:complexType>
53+
</xs:element>
54+
</xs:schema>
55+
</wsdl:types>
56+
57+
<wsdl:message name="DummyRequest">
58+
<wsdl:part name="parameters" element="tns:DummyRequest"/>
59+
</wsdl:message>
60+
<wsdl:message name="DummyResponse">
61+
<wsdl:part name="parameters" element="tns:DummyResponse"/>
62+
</wsdl:message>
63+
64+
<wsdl:portType name="DummyPortType">
65+
<wsdl:operation name="Dummy">
66+
<wsdl:input message="tns:DummyRequest"/>
67+
<wsdl:output message="tns:DummyResponse"/>
68+
</wsdl:operation>
69+
</wsdl:portType>
70+
71+
<wsdl:binding name="DummyBinding" type="tns:DummyPortType">
72+
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
73+
<wsdl:operation name="Dummy">
74+
<soap:operation soapAction="Dummy"/>
75+
<wsdl:input>
76+
<soap:body use="literal"/>
77+
</wsdl:input>
78+
<wsdl:output>
79+
<soap:body use="literal"/>
80+
</wsdl:output>
81+
</wsdl:operation>
82+
</wsdl:binding>
83+
84+
<wsdl:service name="DummyService">
85+
<wsdl:port name="DummyPort" binding="tns:DummyBinding">
86+
<soap:address location="http://localhost:1509/test"/>
87+
</wsdl:port>
88+
</wsdl:service>
89+
90+
</wsdl:definitions>

0 commit comments

Comments
 (0)