diff --git a/src/wsdl/index.ts b/src/wsdl/index.ts index 42b9d8e28..9378505c0 100644 --- a/src/wsdl/index.ts +++ b/src/wsdl/index.ts @@ -367,7 +367,12 @@ export class WSDL { const topSchema = top.schema; const name = splitQName(nsName).name; - if (typeof cur.schema === 'string' && (cur.schema === 'string' || cur.schema.split(':')[1] === 'string')) { + /** + * When parsing a string element, we need to correctly transform `` + * to an empty string. + */ + const isStringElement = typeof cur.schema === 'string' && splitQName(cur.schema).name === 'string'; + if (isStringElement) { if (typeof obj === 'object' && Object.keys(obj).length === 0) { obj = cur.object = this.options.preserveWhitespace ? cur.text || '' : ''; } diff --git a/test/request-response-samples/Dummy__should_handle_empty_string_with_pattern_restriction/request.json b/test/request-response-samples/Dummy__should_handle_empty_string_with_pattern_restriction/request.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/test/request-response-samples/Dummy__should_handle_empty_string_with_pattern_restriction/request.json @@ -0,0 +1 @@ +{} diff --git a/test/request-response-samples/Dummy__should_handle_empty_string_with_pattern_restriction/request.xml b/test/request-response-samples/Dummy__should_handle_empty_string_with_pattern_restriction/request.xml new file mode 100644 index 000000000..975d95ab1 --- /dev/null +++ b/test/request-response-samples/Dummy__should_handle_empty_string_with_pattern_restriction/request.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/test/request-response-samples/Dummy__should_handle_empty_string_with_pattern_restriction/response.json b/test/request-response-samples/Dummy__should_handle_empty_string_with_pattern_restriction/response.json new file mode 100644 index 000000000..520fb5ddf --- /dev/null +++ b/test/request-response-samples/Dummy__should_handle_empty_string_with_pattern_restriction/response.json @@ -0,0 +1,8 @@ +{ + "foo": { + "string_simple": "", + "string_pattern": "", + "string_simple_list": [""], + "string_pattern_list": [""] + } +} diff --git a/test/request-response-samples/Dummy__should_handle_empty_string_with_pattern_restriction/response.xml b/test/request-response-samples/Dummy__should_handle_empty_string_with_pattern_restriction/response.xml new file mode 100644 index 000000000..26232a647 --- /dev/null +++ b/test/request-response-samples/Dummy__should_handle_empty_string_with_pattern_restriction/response.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/request-response-samples/Dummy__should_handle_empty_string_with_pattern_restriction/soap.wsdl b/test/request-response-samples/Dummy__should_handle_empty_string_with_pattern_restriction/soap.wsdl new file mode 100644 index 000000000..40c1e3a3b --- /dev/null +++ b/test/request-response-samples/Dummy__should_handle_empty_string_with_pattern_restriction/soap.wsdl @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +