Skip to content

Commit c7dbbe5

Browse files
committed
fix(profile): tolerate malformed base64 titles
1 parent 11c7e08 commit c7dbbe5

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

lib/features/profile/data/profile_parser.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,11 @@ class ProfileParser {
357357

358358
if (headers['profile-title'] case final String titleHeader when name.isBlank) {
359359
if (titleHeader.startsWith("base64:")) {
360-
name = utf8.decode(base64.decode(titleHeader.replaceFirst("base64:", "")));
360+
try {
361+
name = utf8.decode(base64.decode(titleHeader.replaceFirst("base64:", "")));
362+
} on FormatException {
363+
// Ignore malformed optional metadata and continue through the fallback hierarchy.
364+
}
361365
} else {
362366
name = titleHeader.trim();
363367
}

test/features/profile/data/profile_parser_test.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,26 @@ void main() {
160160
});
161161
});
162162

163+
test("Should fall back when the base64 title is malformed", () {
164+
expectRemote(
165+
parseRemoteWithHeaders(
166+
{"profile-title": "base64:not valid base64!!"},
167+
url: "https://example.com/config#fallback",
168+
),
169+
(rp) => expect(rp.name, equals("fallback")),
170+
);
171+
});
172+
173+
test("Should fall back when the base64 title is invalid UTF-8", () {
174+
expectRemote(
175+
parseRemoteWithHeaders(
176+
{"profile-title": "base64:/w=="},
177+
url: "https://example.com/config#fallback",
178+
),
179+
(rp) => expect(rp.name, equals("fallback")),
180+
);
181+
});
182+
163183
test("Should keep web page and support urls without subscription-userinfo", () {
164184
final headers = <String, List<String>>{
165185
"profile-title": ["title"],

0 commit comments

Comments
 (0)