applyQueryCensors method

String applyQueryCensors(
  1. String url
)

Applies the query parameter censors to the given url.

Implementation

String applyQueryCensors(String url) {
  if (_queryElementsToCensor.isEmpty) {
    // short circuit if there are no censors to apply
    return url;
  }

  Uri uri = Uri.parse(url);

  Map<String, dynamic> newQueryParameters = <String, dynamic>{};

  uri.queryParameters.forEach((key, value) {
    if (elementShouldBeCensored(key, _queryElementsToCensor)) {
      newQueryParameters[key] = _censorString;
    } else {
      newQueryParameters[key] = value;
    }
  });

  return Uri(
    scheme: uri.scheme,
    userInfo: uri.userInfo,
    host: uri.host,
    port: uri.port,
    path: uri.path,
    queryParameters: newQueryParameters,
  ).toString();
}