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:
1 parent
ee382f9177
commit
69693f5a89
3 files changed
+87
-86
No files matched your search
@@ -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'] ?? '');
|
||||
|
||||
@@ -34,6 +34,18 @@ void main() {
|
||||
expect(config.action, isNull);
|
||||
});
|
||||
|
||||
test('accepts plain-text values', () {
|
||||
final config = NodeBannerConfig.parse(
|
||||
'v=1;on=1;url=https://shop.example.com/node?ref=a&b=c;'
|
||||
'title=Need a new node?;body=Waterproof, 50% off this week.;'
|
||||
'cta=Get one here',
|
||||
)!;
|
||||
expect(config.url.toString(), 'https://shop.example.com/node?ref=a&b=c');
|
||||
expect(config.title, 'Need a new node?');
|
||||
expect(config.body, 'Waterproof, 50% off this week.');
|
||||
expect(config.action, 'Get one here');
|
||||
});
|
||||
|
||||
test('is off for on=0, unknown versions, and non-https links', () {
|
||||
expect(
|
||||
NodeBannerConfig.parse(_record.replaceAll('on=1', 'on=0')),
|
||||
|
||||
+68
-82
@@ -1,134 +1,120 @@
|
||||
{
|
||||
"bg": [
|
||||
"channels_notificationModeTooltip"
|
||||
"settings_pathHashModeNotApplied",
|
||||
"channels_notificationModeTooltip",
|
||||
"notification_lowBatteryTitle",
|
||||
"notification_lowBatteryBody"
|
||||
],
|
||||
|
||||
"de": [
|
||||
"channels_notificationModeTooltip"
|
||||
"settings_pathHashModeNotApplied",
|
||||
"channels_notificationModeTooltip",
|
||||
"notification_lowBatteryTitle",
|
||||
"notification_lowBatteryBody"
|
||||
],
|
||||
|
||||
"es": [
|
||||
"channels_notificationModeTooltip"
|
||||
"settings_pathHashModeNotApplied",
|
||||
"channels_notificationModeTooltip",
|
||||
"notification_lowBatteryTitle",
|
||||
"notification_lowBatteryBody"
|
||||
],
|
||||
|
||||
"fr": [
|
||||
"channels_notificationModeTooltip"
|
||||
"settings_pathHashModeNotApplied",
|
||||
"channels_notificationModeTooltip",
|
||||
"notification_lowBatteryTitle",
|
||||
"notification_lowBatteryBody"
|
||||
],
|
||||
|
||||
"hu": [
|
||||
"channels_notificationModeTooltip"
|
||||
"settings_pathHashModeNotApplied",
|
||||
"channels_notificationModeTooltip",
|
||||
"notification_lowBatteryTitle",
|
||||
"notification_lowBatteryBody"
|
||||
],
|
||||
|
||||
"it": [
|
||||
"channels_notificationModeTooltip"
|
||||
"settings_pathHashModeNotApplied",
|
||||
"channels_notificationModeTooltip",
|
||||
"notification_lowBatteryTitle",
|
||||
"notification_lowBatteryBody"
|
||||
],
|
||||
|
||||
"ja": [
|
||||
"channels_notificationModeTooltip"
|
||||
"settings_pathHashModeNotApplied",
|
||||
"channels_notificationModeTooltip",
|
||||
"notification_lowBatteryTitle",
|
||||
"notification_lowBatteryBody"
|
||||
],
|
||||
|
||||
"ko": [
|
||||
"channels_notificationModeTooltip"
|
||||
"settings_pathHashModeNotApplied",
|
||||
"channels_notificationModeTooltip",
|
||||
"notification_lowBatteryTitle",
|
||||
"notification_lowBatteryBody"
|
||||
],
|
||||
|
||||
"nl": [
|
||||
"channels_notificationModeTooltip"
|
||||
"settings_pathHashModeNotApplied",
|
||||
"channels_notificationModeTooltip",
|
||||
"notification_lowBatteryTitle",
|
||||
"notification_lowBatteryBody"
|
||||
],
|
||||
|
||||
"pl": [
|
||||
"channels_notificationModeTooltip"
|
||||
"settings_pathHashModeNotApplied",
|
||||
"channels_notificationModeTooltip",
|
||||
"notification_lowBatteryTitle",
|
||||
"notification_lowBatteryBody"
|
||||
],
|
||||
|
||||
"pt": [
|
||||
"channels_notificationModeTooltip"
|
||||
"settings_pathHashModeNotApplied",
|
||||
"channels_notificationModeTooltip",
|
||||
"notification_lowBatteryTitle",
|
||||
"notification_lowBatteryBody"
|
||||
],
|
||||
|
||||
"ru": [
|
||||
"channels_notificationModeTooltip"
|
||||
"settings_pathHashModeNotApplied",
|
||||
"channels_notificationModeTooltip",
|
||||
"notification_lowBatteryTitle",
|
||||
"notification_lowBatteryBody"
|
||||
],
|
||||
|
||||
"sk": [
|
||||
"channels_notificationModeTooltip"
|
||||
"settings_pathHashModeNotApplied",
|
||||
"channels_notificationModeTooltip",
|
||||
"notification_lowBatteryTitle",
|
||||
"notification_lowBatteryBody"
|
||||
],
|
||||
|
||||
"sl": [
|
||||
"channels_notificationModeTooltip"
|
||||
"settings_pathHashModeNotApplied",
|
||||
"channels_notificationModeTooltip",
|
||||
"notification_lowBatteryTitle",
|
||||
"notification_lowBatteryBody"
|
||||
],
|
||||
|
||||
"sv": [
|
||||
"channels_notificationModeTooltip"
|
||||
"settings_pathHashModeNotApplied",
|
||||
"channels_notificationModeTooltip",
|
||||
"notification_lowBatteryTitle",
|
||||
"notification_lowBatteryBody"
|
||||
],
|
||||
|
||||
"uk": [
|
||||
"channels_notificationModeTooltip"
|
||||
"settings_pathHashModeNotApplied",
|
||||
"channels_notificationModeTooltip",
|
||||
"notification_lowBatteryTitle",
|
||||
"notification_lowBatteryBody"
|
||||
],
|
||||
|
||||
"zh": [
|
||||
"channels_notificationModeTooltip"
|
||||
"settings_pathHashModeNotApplied"
|
||||
],
|
||||
|
||||
"de": [
|
||||
"settings_pathHashModeNotApplied"
|
||||
],
|
||||
|
||||
"es": [
|
||||
"settings_pathHashModeNotApplied"
|
||||
],
|
||||
|
||||
"fr": [
|
||||
"settings_pathHashModeNotApplied"
|
||||
],
|
||||
|
||||
"hu": [
|
||||
"settings_pathHashModeNotApplied"
|
||||
],
|
||||
|
||||
"it": [
|
||||
"settings_pathHashModeNotApplied"
|
||||
],
|
||||
|
||||
"ja": [
|
||||
"settings_pathHashModeNotApplied"
|
||||
],
|
||||
|
||||
"ko": [
|
||||
"settings_pathHashModeNotApplied"
|
||||
],
|
||||
|
||||
"nl": [
|
||||
"settings_pathHashModeNotApplied"
|
||||
],
|
||||
|
||||
"pl": [
|
||||
"settings_pathHashModeNotApplied"
|
||||
],
|
||||
|
||||
"pt": [
|
||||
"settings_pathHashModeNotApplied"
|
||||
],
|
||||
|
||||
"ru": [
|
||||
"settings_pathHashModeNotApplied"
|
||||
],
|
||||
|
||||
"sk": [
|
||||
"settings_pathHashModeNotApplied"
|
||||
],
|
||||
|
||||
"sl": [
|
||||
"settings_pathHashModeNotApplied"
|
||||
],
|
||||
|
||||
"sv": [
|
||||
"settings_pathHashModeNotApplied"
|
||||
],
|
||||
|
||||
"uk": [
|
||||
"settings_pathHashModeNotApplied"
|
||||
],
|
||||
|
||||
"zh": [
|
||||
"settings_pathHashModeNotApplied"
|
||||
"settings_pathHashModeNotApplied",
|
||||
"channels_notificationModeTooltip",
|
||||
"notification_lowBatteryTitle",
|
||||
"notification_lowBatteryBody"
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user