validate method

void validate(
  1. List<Rule> rules
)

Validates the format of the provided rules.

The content of rules is validated against the expected format as described on publicsuffix.org. rules is expected to first have been passed through process.

In brief:

  • Rules should not start with a period (.)
  • Rules may contain asterisks (*) as wildcards
    • Wildcards must be surrounded by periods or the line start/end
    • Example: *.uk is valid, c*.uk is not
  • Rules that start with exclamation marks (!) mark exceptions to previous rules
    • Example: !co.uk would exclude co.uk from *.uk

If at least one rule in the list is invalid, a FormatException is thrown containing information about the amount of invalid lines in the message.

Implementation

void validate(List<Rule> rules) {
  var invalidRules = 0;

  for (var rule in rules) {
    if (_isComment(rule.labels) ||
        _isEmpty(rule.labels) ||
        !_isValidRule(rule.labels)) {
      invalidRules++;
    }
  }

  if (invalidRules > 0) {
    throw FormatException(
        'Invalid suffix list: $invalidRules/${rules.length} lines are not formatted properly!');
  }
}