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,
|
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
|
/// Returns null when the banner is switched off (`on=0`), the version is
|
||||||
/// unknown, or the link is missing or not https.
|
/// unknown, or the link is missing or not https.
|
||||||
static NodeBannerConfig? parse(String record) {
|
static NodeBannerConfig? parse(String record) {
|
||||||
@@ -37,12 +38,14 @@ class NodeBannerConfig {
|
|||||||
for (final pair in record.split(';')) {
|
for (final pair in record.split(';')) {
|
||||||
final eq = pair.indexOf('=');
|
final eq = pair.indexOf('=');
|
||||||
if (eq <= 0) continue;
|
if (eq <= 0) continue;
|
||||||
|
final raw = pair.substring(eq + 1).trim();
|
||||||
|
String value;
|
||||||
try {
|
try {
|
||||||
fields[pair.substring(0, eq).trim().toLowerCase()] =
|
value = Uri.decodeComponent(raw);
|
||||||
Uri.decodeComponent(pair.substring(eq + 1).trim());
|
|
||||||
} on ArgumentError {
|
} on ArgumentError {
|
||||||
return null;
|
value = raw;
|
||||||
}
|
}
|
||||||
|
fields[pair.substring(0, eq).trim().toLowerCase()] = value;
|
||||||
}
|
}
|
||||||
if (fields['v'] != '1' || fields['on'] != '1') return null;
|
if (fields['v'] != '1' || fields['on'] != '1') return null;
|
||||||
final url = Uri.tryParse(fields['url'] ?? '');
|
final url = Uri.tryParse(fields['url'] ?? '');
|
||||||
|
|||||||
@@ -34,6 +34,18 @@ void main() {
|
|||||||
expect(config.action, isNull);
|
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', () {
|
test('is off for on=0, unknown versions, and non-https links', () {
|
||||||
expect(
|
expect(
|
||||||
NodeBannerConfig.parse(_record.replaceAll('on=1', 'on=0')),
|
NodeBannerConfig.parse(_record.replaceAll('on=1', 'on=0')),
|
||||||
|
|||||||
+68
-82
@@ -1,134 +1,120 @@
|
|||||||
{
|
{
|
||||||
"bg": [
|
"bg": [
|
||||||
"channels_notificationModeTooltip"
|
"settings_pathHashModeNotApplied",
|
||||||
|
"channels_notificationModeTooltip",
|
||||||
|
"notification_lowBatteryTitle",
|
||||||
|
"notification_lowBatteryBody"
|
||||||
],
|
],
|
||||||
|
|
||||||
"de": [
|
"de": [
|
||||||
"channels_notificationModeTooltip"
|
"settings_pathHashModeNotApplied",
|
||||||
|
"channels_notificationModeTooltip",
|
||||||
|
"notification_lowBatteryTitle",
|
||||||
|
"notification_lowBatteryBody"
|
||||||
],
|
],
|
||||||
|
|
||||||
"es": [
|
"es": [
|
||||||
"channels_notificationModeTooltip"
|
"settings_pathHashModeNotApplied",
|
||||||
|
"channels_notificationModeTooltip",
|
||||||
|
"notification_lowBatteryTitle",
|
||||||
|
"notification_lowBatteryBody"
|
||||||
],
|
],
|
||||||
|
|
||||||
"fr": [
|
"fr": [
|
||||||
"channels_notificationModeTooltip"
|
"settings_pathHashModeNotApplied",
|
||||||
|
"channels_notificationModeTooltip",
|
||||||
|
"notification_lowBatteryTitle",
|
||||||
|
"notification_lowBatteryBody"
|
||||||
],
|
],
|
||||||
|
|
||||||
"hu": [
|
"hu": [
|
||||||
"channels_notificationModeTooltip"
|
"settings_pathHashModeNotApplied",
|
||||||
|
"channels_notificationModeTooltip",
|
||||||
|
"notification_lowBatteryTitle",
|
||||||
|
"notification_lowBatteryBody"
|
||||||
],
|
],
|
||||||
|
|
||||||
"it": [
|
"it": [
|
||||||
"channels_notificationModeTooltip"
|
"settings_pathHashModeNotApplied",
|
||||||
|
"channels_notificationModeTooltip",
|
||||||
|
"notification_lowBatteryTitle",
|
||||||
|
"notification_lowBatteryBody"
|
||||||
],
|
],
|
||||||
|
|
||||||
"ja": [
|
"ja": [
|
||||||
"channels_notificationModeTooltip"
|
"settings_pathHashModeNotApplied",
|
||||||
|
"channels_notificationModeTooltip",
|
||||||
|
"notification_lowBatteryTitle",
|
||||||
|
"notification_lowBatteryBody"
|
||||||
],
|
],
|
||||||
|
|
||||||
"ko": [
|
"ko": [
|
||||||
"channels_notificationModeTooltip"
|
"settings_pathHashModeNotApplied",
|
||||||
|
"channels_notificationModeTooltip",
|
||||||
|
"notification_lowBatteryTitle",
|
||||||
|
"notification_lowBatteryBody"
|
||||||
],
|
],
|
||||||
|
|
||||||
"nl": [
|
"nl": [
|
||||||
"channels_notificationModeTooltip"
|
"settings_pathHashModeNotApplied",
|
||||||
|
"channels_notificationModeTooltip",
|
||||||
|
"notification_lowBatteryTitle",
|
||||||
|
"notification_lowBatteryBody"
|
||||||
],
|
],
|
||||||
|
|
||||||
"pl": [
|
"pl": [
|
||||||
"channels_notificationModeTooltip"
|
"settings_pathHashModeNotApplied",
|
||||||
|
"channels_notificationModeTooltip",
|
||||||
|
"notification_lowBatteryTitle",
|
||||||
|
"notification_lowBatteryBody"
|
||||||
],
|
],
|
||||||
|
|
||||||
"pt": [
|
"pt": [
|
||||||
"channels_notificationModeTooltip"
|
"settings_pathHashModeNotApplied",
|
||||||
|
"channels_notificationModeTooltip",
|
||||||
|
"notification_lowBatteryTitle",
|
||||||
|
"notification_lowBatteryBody"
|
||||||
],
|
],
|
||||||
|
|
||||||
"ru": [
|
"ru": [
|
||||||
"channels_notificationModeTooltip"
|
"settings_pathHashModeNotApplied",
|
||||||
|
"channels_notificationModeTooltip",
|
||||||
|
"notification_lowBatteryTitle",
|
||||||
|
"notification_lowBatteryBody"
|
||||||
],
|
],
|
||||||
|
|
||||||
"sk": [
|
"sk": [
|
||||||
"channels_notificationModeTooltip"
|
"settings_pathHashModeNotApplied",
|
||||||
|
"channels_notificationModeTooltip",
|
||||||
|
"notification_lowBatteryTitle",
|
||||||
|
"notification_lowBatteryBody"
|
||||||
],
|
],
|
||||||
|
|
||||||
"sl": [
|
"sl": [
|
||||||
"channels_notificationModeTooltip"
|
"settings_pathHashModeNotApplied",
|
||||||
|
"channels_notificationModeTooltip",
|
||||||
|
"notification_lowBatteryTitle",
|
||||||
|
"notification_lowBatteryBody"
|
||||||
],
|
],
|
||||||
|
|
||||||
"sv": [
|
"sv": [
|
||||||
"channels_notificationModeTooltip"
|
"settings_pathHashModeNotApplied",
|
||||||
|
"channels_notificationModeTooltip",
|
||||||
|
"notification_lowBatteryTitle",
|
||||||
|
"notification_lowBatteryBody"
|
||||||
],
|
],
|
||||||
|
|
||||||
"uk": [
|
"uk": [
|
||||||
"channels_notificationModeTooltip"
|
"settings_pathHashModeNotApplied",
|
||||||
|
"channels_notificationModeTooltip",
|
||||||
|
"notification_lowBatteryTitle",
|
||||||
|
"notification_lowBatteryBody"
|
||||||
],
|
],
|
||||||
|
|
||||||
"zh": [
|
"zh": [
|
||||||
"channels_notificationModeTooltip"
|
"settings_pathHashModeNotApplied",
|
||||||
"settings_pathHashModeNotApplied"
|
"channels_notificationModeTooltip",
|
||||||
],
|
"notification_lowBatteryTitle",
|
||||||
|
"notification_lowBatteryBody"
|
||||||
"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"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user