-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core-xml] fix stringifyXML missing XML namespace issue on Firefox (#…
…31021) Chrome-based browsers are more error-tolerant when the XML namespace ("xmlns:...") was set via attribute, but that doesn't work on Firefox, which requires using of `createElementNS()` to create element with XML namespace. This PR adds special handling of the "xmlns" attribute. ------- ### Packages impacted by this PR @azure/core-xml ### Issues associated with this PR #11655 #30979
- Loading branch information
1 parent
df493c5
commit ee6f42e
Showing
8 changed files
with
279 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
sdk/core/core-client/test/browser/serializationPolicyXML.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { describe, it, assert } from "vitest"; | ||
import { MapperTypeNames, createSerializer } from "../../src/index.js"; | ||
import { serializeRequestBody } from "../../src/serializationPolicy.js"; | ||
import { createPipelineRequest } from "@azure/core-rest-pipeline"; | ||
import { stringifyXML } from "@azure/core-xml"; | ||
|
||
describe("serializationPolicy", function () { | ||
describe("serializeRequestBody()", () => { | ||
it("should serialize an XML Composite request body with namespace and prefix", () => { | ||
const httpRequest = createPipelineRequest({ url: "https://example.com" }); | ||
serializeRequestBody( | ||
httpRequest, | ||
{ | ||
bodyArg: { foo: "Foo", bar: "Bar" }, | ||
}, | ||
{ | ||
httpMethod: "POST", | ||
requestBody: { | ||
parameterPath: "bodyArg", | ||
mapper: { | ||
required: true, | ||
serializedName: "bodyArg", | ||
xmlNamespace: "https://microsoft.com", | ||
type: { | ||
name: MapperTypeNames.Composite, | ||
modelProperties: { | ||
foo: { | ||
serializedName: "foo", | ||
xmlNamespace: "https://microsoft.com/foo", | ||
xmlName: "Foo", | ||
type: { | ||
name: "String", | ||
}, | ||
}, | ||
bar: { | ||
xmlNamespacePrefix: "bar", | ||
xmlNamespace: "https://microsoft.com/bar", | ||
xmlName: "Bar", | ||
serializedName: "bar", | ||
type: { | ||
name: "String", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
responses: { 200: {} }, | ||
serializer: createSerializer(undefined, true /** isXML */), | ||
isXML: true, | ||
}, | ||
stringifyXML, | ||
); | ||
assert.strictEqual( | ||
httpRequest.body, | ||
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?><bodyArg xmlns="https://microsoft.com"><Foo xmlns="https://microsoft.com/foo">Foo</Foo><Bar xmlns:bar="https://microsoft.com/bar">Bar</Bar></bodyArg>`, | ||
); | ||
}); | ||
|
||
it("should serialize an XML Array of composite elements, namespace and prefix", () => { | ||
const httpRequest = createPipelineRequest({ url: "https://example.com" }); | ||
serializeRequestBody( | ||
httpRequest, | ||
{ | ||
bodyArg: [ | ||
{ foo: "Foo1", bar: "Bar1" }, | ||
{ foo: "Foo2", bar: "Bar2" }, | ||
{ foo: "Foo3", bar: "Bar3" }, | ||
], | ||
}, | ||
{ | ||
httpMethod: "POST", | ||
requestBody: { | ||
parameterPath: "bodyArg", | ||
mapper: { | ||
required: true, | ||
serializedName: "bodyArg", | ||
xmlNamespace: "https://microsoft.com", | ||
xmlElementName: "testItem", | ||
type: { | ||
name: MapperTypeNames.Sequence, | ||
element: { | ||
xmlNamespace: "https://microsoft.com/element", | ||
type: { | ||
name: "Composite", | ||
modelProperties: { | ||
foo: { | ||
serializedName: "foo", | ||
xmlNamespace: "https://microsoft.com/foo", | ||
xmlName: "Foo", | ||
type: { | ||
name: "String", | ||
}, | ||
}, | ||
bar: { | ||
xmlNamespacePrefix: "bar", | ||
xmlNamespace: "https://microsoft.com/bar", | ||
xmlName: "Bar", | ||
serializedName: "bar", | ||
type: { | ||
name: "String", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
responses: { 200: {} }, | ||
serializer: createSerializer(undefined, true /** isXML */), | ||
isXML: true, | ||
}, | ||
stringifyXML, | ||
); | ||
assert.strictEqual( | ||
httpRequest.body, | ||
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?><bodyArg xmlns="https://microsoft.com"><testItem xmlns="https://microsoft.com/element"><Foo xmlns="https://microsoft.com/foo">Foo1</Foo><Bar xmlns:bar="https://microsoft.com/bar">Bar1</Bar></testItem><testItem xmlns="https://microsoft.com/element"><Foo xmlns="https://microsoft.com/foo">Foo2</Foo><Bar xmlns:bar="https://microsoft.com/bar">Bar2</Bar></testItem><testItem xmlns="https://microsoft.com/element"><Foo xmlns="https://microsoft.com/foo">Foo3</Foo><Bar xmlns:bar="https://microsoft.com/bar">Bar3</Bar></testItem></bodyArg>`, | ||
); | ||
}); | ||
}); | ||
}); |
125 changes: 125 additions & 0 deletions
125
sdk/core/core-client/test/node/serializationPolicyXML.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { describe, it, assert } from "vitest"; | ||
import { MapperTypeNames, createSerializer } from "../../src/index.js"; | ||
import { serializeRequestBody } from "../../src/serializationPolicy.js"; | ||
import { createPipelineRequest } from "@azure/core-rest-pipeline"; | ||
import { stringifyXML } from "@azure/core-xml"; | ||
|
||
describe("serializationPolicy", function () { | ||
describe("serializeRequestBody()", () => { | ||
it("should serialize an XML Composite request body with namespace and prefix", () => { | ||
const httpRequest = createPipelineRequest({ url: "https://example.com" }); | ||
serializeRequestBody( | ||
httpRequest, | ||
{ | ||
bodyArg: { foo: "Foo", bar: "Bar" }, | ||
}, | ||
{ | ||
httpMethod: "POST", | ||
requestBody: { | ||
parameterPath: "bodyArg", | ||
mapper: { | ||
required: true, | ||
serializedName: "bodyArg", | ||
xmlNamespace: "https://microsoft.com", | ||
type: { | ||
name: MapperTypeNames.Composite, | ||
modelProperties: { | ||
foo: { | ||
serializedName: "foo", | ||
xmlNamespace: "https://microsoft.com/foo", | ||
xmlName: "Foo", | ||
type: { | ||
name: "String", | ||
}, | ||
}, | ||
bar: { | ||
xmlNamespacePrefix: "bar", | ||
xmlNamespace: "https://microsoft.com/bar", | ||
xmlName: "Bar", | ||
serializedName: "bar", | ||
type: { | ||
name: "String", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
responses: { 200: {} }, | ||
serializer: createSerializer(undefined, true /** isXML */), | ||
isXML: true, | ||
}, | ||
stringifyXML, | ||
); | ||
assert.strictEqual( | ||
httpRequest.body, | ||
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?><bodyArg xmlns="https://microsoft.com"><Foo xmlns="https://microsoft.com/foo">Foo</Foo><Bar xmlns:bar="https://microsoft.com/bar">Bar</Bar></bodyArg>`, | ||
); | ||
}); | ||
|
||
it("should serialize an XML Array of composite elements, namespace and prefix", () => { | ||
const httpRequest = createPipelineRequest({ url: "https://example.com" }); | ||
serializeRequestBody( | ||
httpRequest, | ||
{ | ||
bodyArg: [ | ||
{ foo: "Foo1", bar: "Bar1" }, | ||
{ foo: "Foo2", bar: "Bar2" }, | ||
{ foo: "Foo3", bar: "Bar3" }, | ||
], | ||
}, | ||
{ | ||
httpMethod: "POST", | ||
requestBody: { | ||
parameterPath: "bodyArg", | ||
mapper: { | ||
required: true, | ||
serializedName: "bodyArg", | ||
xmlNamespace: "https://microsoft.com", | ||
xmlElementName: "testItem", | ||
type: { | ||
name: MapperTypeNames.Sequence, | ||
element: { | ||
xmlNamespace: "https://microsoft.com/element", | ||
type: { | ||
name: "Composite", | ||
modelProperties: { | ||
foo: { | ||
serializedName: "foo", | ||
xmlNamespace: "https://microsoft.com/foo", | ||
xmlName: "Foo", | ||
type: { | ||
name: "String", | ||
}, | ||
}, | ||
bar: { | ||
xmlNamespacePrefix: "bar", | ||
xmlNamespace: "https://microsoft.com/bar", | ||
xmlName: "Bar", | ||
serializedName: "bar", | ||
type: { | ||
name: "String", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
responses: { 200: {} }, | ||
serializer: createSerializer(undefined, true /** isXML */), | ||
isXML: true, | ||
}, | ||
stringifyXML, | ||
); | ||
assert.strictEqual( | ||
httpRequest.body, | ||
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?><bodyArg xmlns="https://microsoft.com"><testItem xmlns="https://microsoft.com/element"><Foo xmlns="https://microsoft.com/foo">Foo1</Foo><Bar xmlns:bar="https://microsoft.com/bar">Bar1</Bar></testItem><testItem xmlns="https://microsoft.com/element"><Foo xmlns="https://microsoft.com/foo">Foo2</Foo><Bar xmlns:bar="https://microsoft.com/bar">Bar2</Bar></testItem><testItem xmlns="https://microsoft.com/element"><Foo xmlns="https://microsoft.com/foo">Foo3</Foo><Bar xmlns:bar="https://microsoft.com/bar">Bar3</Bar></testItem></bodyArg>`, | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.