Accept plain-text values in the node banner record

Only ';' needs encoding, so the title and body fit in one TXT string.
Values that aren't valid percent-encoding are used as-is instead of
hiding the banner.
This commit is contained in:
zjs81 committed 2026-10-24 21:33:14 -07:00
1 parent ee382f9177
commit 69693f5a89
3 files changed
+87 -86

No files matched your search

+7 -4
View File
@@ -29,7 +29,8 @@ class NodeBannerConfig {
this.action,
});
/// Parses `key=value` pairs separated by `;` with URL-encoded values.
/// Parses `key=value` pairs separated by `;`. Values may be plain text;
/// percent-encoding is decoded when valid, so `%3B` can carry a `;`.
/// Returns null when the banner is switched off (`on=0`), the version is
/// unknown, or the link is missing or not https.
static NodeBannerConfig? parse(String record) {
@@ -37,12 +38,14 @@ class NodeBannerConfig {
for (final pair in record.split(';')) {
final eq = pair.indexOf('=');
if (eq <= 0) continue;
final raw = pair.substring(eq + 1).trim();
String value;
try {
fields[pair.substring(0, eq).trim().toLowerCase()] =
Uri.decodeComponent(pair.substring(eq + 1).trim());
value = Uri.decodeComponent(raw);
} on ArgumentError {
return null;
value = raw;
}
fields[pair.substring(0, eq).trim().toLowerCase()] = value;
}
if (fields['v'] != '1' || fields['on'] != '1') return null;
final url = Uri.tryParse(fields['url'] ?? '');