decodeXhttpExtra method
Decodes the XHTTP extra JSON object from URL query parameters.
Some subscriptions double-encode this field, so decoding is attempted a few times before parsing JSON. Invalid data is dropped instead of emitting malformed Xray config, which would hide the actual transport failure.
Implementation
Map<String, dynamic>? decodeXhttpExtra(String? extra) {
if (extra == null || extra.isEmpty) {
return null;
}
String candidate = extra;
for (var i = 0; i < 3; i++) {
try {
final decoded = Uri.decodeComponent(candidate);
if (decoded == candidate) {
break;
}
candidate = decoded;
} catch (_) {
break;
}
}
try {
final decoded = jsonDecode(candidate);
return decoded is Map<String, dynamic> ? decoded : null;
} catch (_) {
return null;
}
}