Skip to content

Commit 6edc3b5

Browse files
authored
[notification hubs] Fix empty registration feed bug (Azure#23121)
1 parent a4367c4 commit 6edc3b5

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

sdk/notificationhubs/notification-hubs/src/serializers/registrationSerializer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,11 @@ export const registrationDescriptionParser: RegistrationDescriptionParser = {
187187
*/
188188
async parseRegistrationFeed(bodyText: string): Promise<RegistrationDescription[]> {
189189
const xml = await parseXML(bodyText, { includeRoot: true });
190-
const results = [];
190+
const results: RegistrationDescription[] = [];
191+
if (!isDefined(xml.feed.entry)) {
192+
return results;
193+
}
194+
191195
for (const entry of xml.feed.entry) {
192196
delete entry.content["$"];
193197

sdk/notificationhubs/notification-hubs/test/internal/unit/registrationSerializer.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,14 @@ const REGISTRATION_FEED = `<?xml version="1.0" encoding="utf-8" ?>
491491
</entry>
492492
</feed>`;
493493

494+
const EMPTY_REGISTRATION_FEED = `<?xml version="1.0" encoding="utf-8" ?>
495+
<feed xmlns="http://www.w3.org/2005/Atom">
496+
<title type="text">Registrations</title>
497+
<id>https://testns.servicebus.windows.net/testhub/registrations/?api-version=2020-06</id>
498+
<updated>2022-09-06T20:06:33Z</updated>
499+
<link rel="self" href="https://testns.servicebus.windows.net/testhub/registrations/?api-version=2020-06" />
500+
</feed>`;
501+
494502
describe("parseRegistrationFeed", () => {
495503
it("should parse a registration feed", async () => {
496504
const registrations = await registrationDescriptionParser.parseRegistrationFeed(
@@ -509,6 +517,14 @@ describe("parseRegistrationFeed", () => {
509517
assert.equal(appleRegistration.deviceToken, "{DeviceToken}");
510518
assert.deepEqual(appleRegistration.tags, ["myTag", "myOtherTag"]);
511519
});
520+
521+
it("should parse an empty feed", async () => {
522+
const registrations = await registrationDescriptionParser.parseRegistrationFeed(
523+
EMPTY_REGISTRATION_FEED
524+
);
525+
526+
assert.equal(registrations.length, 0);
527+
});
512528
});
513529

514530
describe("serializeRegistrationDescription", () => {

0 commit comments

Comments
 (0)