Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace whitelist/blacklist with safelist/blocklist #917

Merged
merged 1 commit into from Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/src/configuration.dart
Expand Up @@ -63,9 +63,9 @@ class Configuration {
newValues = UnprefixedMapView(newValues, forward.prefix);
}
if (forward.shownVariables != null) {
newValues = LimitedMapView.whitelist(newValues, forward.shownVariables);
newValues = LimitedMapView.safelist(newValues, forward.shownVariables);
} else if (forward.hiddenVariables?.isNotEmpty ?? false) {
newValues = LimitedMapView.blacklist(newValues, forward.hiddenVariables);
newValues = LimitedMapView.blocklist(newValues, forward.hiddenVariables);
}
return Configuration(newValues, isImplicit: isImplicit);
}
Expand Down
22 changes: 11 additions & 11 deletions lib/src/module/forwarded_view.dart
Expand Up @@ -46,27 +46,27 @@ class ForwardedModuleView<T extends AsyncCallable> implements Module<T> {
mixins = _forwardedMap(_inner.mixins, _rule.prefix,
_rule.shownMixinsAndFunctions, _rule.hiddenMixinsAndFunctions);

/// Wraps [map] so that it only shows members allowed by [blacklist] or
/// [whitelist], with the given [prefix], if given.
/// Wraps [map] so that it only shows members allowed by [blocklist] or
/// [safelist], with the given [prefix], if given.
///
/// Only one of [blacklist] or [whitelist] may be non-`null`.
/// Only one of [blocklist] or [safelist] may be non-`null`.
static Map<String, V> _forwardedMap<V>(Map<String, V> map, String prefix,
Set<String> whitelist, Set<String> blacklist) {
assert(whitelist == null || blacklist == null);
Set<String> safelist, Set<String> blocklist) {
assert(safelist == null || blocklist == null);
if (prefix == null &&
whitelist == null &&
(blacklist == null || blacklist.isEmpty)) {
safelist == null &&
(blocklist == null || blocklist.isEmpty)) {
return map;
}

if (prefix != null) {
map = PrefixedMapView(map, prefix);
}

if (whitelist != null) {
map = LimitedMapView.whitelist(map, whitelist);
} else if (blacklist != null && blacklist.isNotEmpty) {
map = LimitedMapView.blacklist(map, blacklist);
if (safelist != null) {
map = LimitedMapView.safelist(map, safelist);
} else if (blocklist != null && blocklist.isNotEmpty) {
map = LimitedMapView.blocklist(map, blocklist);
}

return map;
Expand Down
16 changes: 8 additions & 8 deletions lib/src/module/shadowed_view.dart
Expand Up @@ -12,7 +12,7 @@ import '../util/limited_map_view.dart';
import '../value.dart';

/// A [Module] that only exposes members that aren't shadowed by a given
/// blacklist of member names.
/// blocklist of member names.
class ShadowedModuleView<T extends AsyncCallable> implements Module<T> {
/// The wrapped module.
final Module<T> _inner;
Expand Down Expand Up @@ -55,16 +55,16 @@ class ShadowedModuleView<T extends AsyncCallable> implements Module<T> {
ShadowedModuleView._(this._inner, this.variables, this.variableNodes,
this.functions, this.mixins);

/// Returns a view of [map] with all keys in [blacklist] omitted.
/// Returns a view of [map] with all keys in [blocklist] omitted.
static Map<String, V> _shadowedMap<V>(
Map<String, V> map, Set<String> blacklist) {
if (map == null || !_needsBlacklist(map, blacklist)) return map;
return LimitedMapView.blacklist(map, blacklist);
Map<String, V> map, Set<String> blocklist) {
if (map == null || !_needsBlacklist(map, blocklist)) return map;
return LimitedMapView.blocklist(map, blocklist);
}

/// Returns whether any of [map]'s keys are in [blacklist].
static bool _needsBlacklist(Map<String, Object> map, Set<String> blacklist) =>
blacklist != null && map.isNotEmpty && blacklist.any(map.containsKey);
/// Returns whether any of [map]'s keys are in [blocklist].
static bool _needsBlacklist(Map<String, Object> map, Set<String> blocklist) =>
blocklist != null && map.isNotEmpty && blocklist.any(map.containsKey);

void setVariable(String name, Value value, AstNode nodeWithSpan) {
if (!variables.containsKey(name)) {
Expand Down
16 changes: 8 additions & 8 deletions lib/src/util/limited_map_view.dart
Expand Up @@ -29,17 +29,17 @@ class LimitedMapView<K, V> extends UnmodifiableMapBase<K, V> {
bool get isEmpty => _keys.isEmpty;
bool get isNotEmpty => _keys.isNotEmpty;

/// Returns a [LimitedMapView] that allows only keys in [whitelist].
/// Returns a [LimitedMapView] that allows only keys in [safelist].
///
/// The [whitelist] must have the same notion of equality as the [map].
LimitedMapView.whitelist(this._map, Set<K> whitelist)
: _keys = whitelist.intersection(MapKeySet(_map));
/// The [safelist] must have the same notion of equality as the [map].
LimitedMapView.safelist(this._map, Set<K> safelist)
: _keys = safelist.intersection(MapKeySet(_map));

/// Returns a [LimitedMapView] that doesn't allow keys in [blacklist].
/// Returns a [LimitedMapView] that doesn't allow keys in [blocklist].
///
/// The [blacklist] must have the same notion of equality as the [map].
LimitedMapView.blacklist(this._map, Set<K> blacklist)
: _keys = {for (var key in _map.keys) if (!blacklist.contains(key)) key};
/// The [blocklist] must have the same notion of equality as the [map].
LimitedMapView.blocklist(this._map, Set<K> blocklist)
: _keys = {for (var key in _map.keys) if (!blocklist.contains(key)) key};

V operator [](Object key) => _keys.contains(key) ? _map[key] : null;
bool containsKey(Object key) => _keys.contains(key);
Expand Down