diff --git a/lib/services/node_banner_service.dart b/lib/services/node_banner_service.dart index 878758e3..3702c537 100644 --- a/lib/services/node_banner_service.dart +++ b/lib/services/node_banner_service.dart @@ -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'] ?? ''); diff --git a/test/services/node_banner_service_test.dart b/test/services/node_banner_service_test.dart index ed6e2bd3..061d7cdf 100644 --- a/test/services/node_banner_service_test.dart +++ b/test/services/node_banner_service_test.dart @@ -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')), diff --git a/untranslated.json b/untranslated.json index 0782702d..1d70f8b5 100644 --- a/untranslated.json +++ b/untranslated.json @@ -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" ] }