From a3e62bb81f5f4c8c4b302c047d33754a4546281c Mon Sep 17 00:00:00 2001 From: Jeremy Meng Date: Fri, 3 Oct 2025 23:59:41 +0000 Subject: [PATCH 1/3] [notification-hubs] fix TypeError when parsing AppleTemplateRegistrationDescription Currently `getHeadersOrUndefined` incorrectly assumes that the `ApnsHeaders` parsed from XML is always an array. However, for single XML element the XML parser gives back an object instead. This change ensures we are iterating over an array. --- .../src/serializers/registrationSerializer.ts | 4 +-- .../unit/registrationSerializer.spec.ts | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/sdk/notificationhubs/notification-hubs/src/serializers/registrationSerializer.ts b/sdk/notificationhubs/notification-hubs/src/serializers/registrationSerializer.ts index 09c3b400861f..1572f06edb92 100644 --- a/sdk/notificationhubs/notification-hubs/src/serializers/registrationSerializer.ts +++ b/sdk/notificationhubs/notification-hubs/src/serializers/registrationSerializer.ts @@ -502,14 +502,14 @@ export const registrationDescriptionParser: RegistrationDescriptionParser = { }; function getHeadersOrUndefined( - value?: { Header: string; Value: string }[], + value?: { Header: string; Value: string }[] | { Header: string; Value: string }, ): Record | undefined { if (!isDefined(value)) { return undefined; } const headerObj: Record = {}; - for (const { Header, Value } of value) { + for (const { Header, Value } of Array.isArray(value) ? value : [value]) { headerObj[Header] = Value; } diff --git a/sdk/notificationhubs/notification-hubs/test/internal/unit/registrationSerializer.spec.ts b/sdk/notificationhubs/notification-hubs/test/internal/unit/registrationSerializer.spec.ts index 3d9d3ccc3f36..2a61a37a82d1 100644 --- a/sdk/notificationhubs/notification-hubs/test/internal/unit/registrationSerializer.spec.ts +++ b/sdk/notificationhubs/notification-hubs/test/internal/unit/registrationSerializer.spec.ts @@ -101,6 +101,24 @@ const APPLE_TEMPLATE_REGISTRATION = ` `; +const APPLE_TEMPLATE_REGISTRATION_SINGLE_APNSHEADER = ` + + + + myTag,myOtherTag + {Registration Id} + {DeviceToken} + + + +
apns-priority
+ 10 +
+
+
+
+
`; + const BAIDU_REGISTRATION = ` @@ -337,6 +355,19 @@ describe("parseRegistrationEntry", () => { assert.equal(registration.apnsHeaders!["apns-expiration"], "0"); }); + it("should parse an apple template registration description with single apns header", async () => { + const registration = (await registrationDescriptionParser.parseRegistrationEntry( + APPLE_TEMPLATE_REGISTRATION_SINGLE_APNSHEADER, + )) as AppleTemplateRegistrationDescription; + + assert.equal(registration.kind, "AppleTemplate"); + assert.equal(registration.registrationId, "{Registration Id}"); + assert.equal(registration.deviceToken, "{DeviceToken}"); + assert.deepEqual(registration.tags, ["myTag", "myOtherTag"]); + assert.equal(registration.bodyTemplate, "{Template for the body}"); + assert.equal(registration.apnsHeaders!["apns-priority"], "10"); + }); + it("should parse an Baidu registration description", async () => { const registration = (await registrationDescriptionParser.parseRegistrationEntry( BAIDU_REGISTRATION, From ce601f3b59334ed1798b52c8b153b8b7303a8f99 Mon Sep 17 00:00:00 2001 From: Jeremy Meng Date: Mon, 6 Oct 2025 16:26:40 +0000 Subject: [PATCH 2/3] update CHANGELOG --- sdk/notificationhubs/notification-hubs/CHANGELOG.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sdk/notificationhubs/notification-hubs/CHANGELOG.md b/sdk/notificationhubs/notification-hubs/CHANGELOG.md index 2b968e581716..70bcc414b5f2 100644 --- a/sdk/notificationhubs/notification-hubs/CHANGELOG.md +++ b/sdk/notificationhubs/notification-hubs/CHANGELOG.md @@ -1,13 +1,11 @@ # Release History -## 2.0.2 (Unreleased) - -### Features Added - -### Breaking Changes +## 2.0.2 (2025-10-07) ### Bugs Fixed +- Properly handle single-element headers of template registrations [PR #36114](https://github.com/Azure/azure-sdk-for-js/pull/36114). + ### Other Changes ## 2.0.0 (2024-10-14) From 4dc7dfa2536d742988fb210caac28274d63bbaa2 Mon Sep 17 00:00:00 2001 From: Jeremy Meng Date: Mon, 6 Oct 2025 17:03:38 +0000 Subject: [PATCH 3/3] fix analyze PR check --- sdk/notificationhubs/notification-hubs/CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/sdk/notificationhubs/notification-hubs/CHANGELOG.md b/sdk/notificationhubs/notification-hubs/CHANGELOG.md index 70bcc414b5f2..1225d9855c56 100644 --- a/sdk/notificationhubs/notification-hubs/CHANGELOG.md +++ b/sdk/notificationhubs/notification-hubs/CHANGELOG.md @@ -6,8 +6,6 @@ - Properly handle single-element headers of template registrations [PR #36114](https://github.com/Azure/azure-sdk-for-js/pull/36114). -### Other Changes - ## 2.0.0 (2024-10-14) ### Features Added