Skip to content

Commit

Permalink
Merge pull request #9 from Komposten/release-3.0.0
Browse files Browse the repository at this point in the history
Release 3.0.0
  • Loading branch information
Komposten authored Apr 1, 2021
2 parents a6704cf + ecc36c9 commit aa79805
Show file tree
Hide file tree
Showing 19 changed files with 185 additions and 121 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/dart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Dart CI

on:
push:
branches:
- master
- develop
- release-*
pull_request:
branches:
- master
- develop
- release-*

jobs:
test:
name: Unit tests
runs-on: ubuntu-latest
strategy:
matrix:
dart_sdk: [ 2.12.0, stable ]

steps:
- name: Install Dart
uses: dart-lang/setup-dart@v1
with:
sdk: ${{ matrix.dart_sdk }}
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
run: pub get
- name: Run tests
run: xvfb-run -a pub run test -p vm,chrome --coverage .coverage
- name: Format test coverage as LCOV
run: pub run coverage:format_coverage --lcov --packages=.packages --report-on lib --in .coverage/ --out .coverage/lcov.info
- name: Upload to CodeCov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./.coverage/lcov.info


analyse:
name: Code analysis
runs-on: ubuntu-latest

container:
image: google/dart:latest

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
run: pub get
- name: Run analyser
run: dartanalyzer lib test example

format:
name: Code format
runs-on: ubuntu-latest

container:
image: google/dart:latest

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Check code format
run: dartfmt -n --set-exit-if-changed .
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 3.0.0
### API changes
- Minimum Dart SDK requirement changed to 2.12.0.
- All components have been updated for the new [null-safety](https://dart.dev/null-safety/understanding-null-safety) system (courtesy of [bsutton](https://github.com/bsutton)).

### Fixes
- Fix a couple of broken references in the API documentation.

## 2.0.1
### Additions
- Add [example/example.md](example/example.md) to make the new examples show up on pub.dev.
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# public_suffix
[![pub package](https://img.shields.io/pub/v/public_suffix.svg)](https://pub.dev/packages/public_suffix)
[![Build Status](https://travis-ci.com/Komposten/public_suffix.svg?branch=master)](https://travis-ci.com/Komposten/public_suffix)
[![Dart CI](https://github.com/Komposten/public_suffix/actions/workflows/dart.yaml/badge.svg)](https://github.com/Komposten/public_suffix/actions/workflows/dart.yaml)
[![codecov](https://codecov.io/gh/Komposten/public_suffix/branch/master/graph/badge.svg)](https://codecov.io/gh/Komposten/public_suffix)

**A domain parser based on the [Public Suffix List](https://publicsuffix.org/)**

Expand All @@ -10,7 +11,7 @@ public_suffix is a dart library for identifying the public suffixes (or TLDs), r
- Identify suffix, root domain, registrable domain (root + suffix) and subdomain from URLs.
- Provide your own list of suffix rules to keep up to date with the rules you need.
- Get results from matching with only ICANN/IANA rules or also include private ones.
- For example, a private rule can see the full `github.io` as suffix while ICANN only recognises the `io` part.
- For example, a private rule can see the full `github.io` as suffix while ICANN only recognises the `io` part.
- Parse punycode encoded URLs and get both encoded and decoded results.
- Check if URLs are subdomains, have valid domain parts, or end with known suffixes.

Expand All @@ -32,22 +33,21 @@ public_suffix is a dart library for identifying the public suffixes (or TLDs), r
import 'package:public_suffix/public_suffix.dart';
main() {
// Load a list of suffix rules from publicsuffix.org.
// Load a list of suffix rules.
var suffixListString = 'load the list into this string';
DefaultSuffixRules.initFromString(suffixListString);
// Parse a URL.
var parsedUrl =
PublicSuffix.fromString('https://www.komposten.github.io');
var parsedUrl = PublicSuffix(urlString: 'https://www.komposten.github.io');
// Obtain information using the many getters, for example:
print(parsedUrl.suffix); // github.io
print(parsedUrl.root); // komposten
print(parsedUrl.domain); // komposten.github.io
print(parsedUrl.icannDomain); // github.io
// public_suffix also supports punycoded URLs:
parsedUrl = PublicSuffix.fromString('https://www.xn--6qq79v.cn');
parsedUrl = PublicSuffix(urlString: 'https://www.xn--6qq79v.cn');
print(parsedUrl.domain); // xn--6qq79v.cn
print(parsedUrl.punyDecoded.domain); // 你好.cn
}
Expand Down Expand Up @@ -112,7 +112,7 @@ Just like before, there are two ways of doing this:
}
```

**Note:** Don't overload publicsuffix.org's servers by repeatedly retrieving the suffix list from them. Cache a copy somewhere instead, and update that copy only when the master copy is updated.
**Note:** Don't overload publicsuffix.org's servers by repeatedly retrieving the suffix list from them. Cache a copy somewhere instead, and update that copy when the master copy is updated.

## Utility functions
Several utility functions can be found in the `DomainUtils` class (imported from `public_suffix.dart`). These currently include:
Expand Down
7 changes: 4 additions & 3 deletions example/instance_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Future<void> main() async {

// Parse a URL.
// Specify a rule list to use that instead of DefaultSuffixRules.
var parsedUrl = PublicSuffix.fromString('https://www.komposten.github.io',
suffixRules: suffixRules);
var parsedUrl = PublicSuffix(
urlString: 'https://www.komposten.github.io', suffixRules: suffixRules);

// Results when matching against both ICANN/IANA and private suffixes.
print(parsedUrl.suffix); // github.io
Expand All @@ -25,7 +25,8 @@ Future<void> main() async {
print(parsedUrl.icannDomain); // github.io

// Punycode decoded results.
parsedUrl = PublicSuffix.fromString('https://www.xn--6qq79v.cn');
parsedUrl = PublicSuffix(
urlString: 'https://www.xn--6qq79v.cn', suffixRules: suffixRules);
print(parsedUrl.domain); // xn--6qq79v.cn
print(parsedUrl.punyDecoded.domain); // 你好.cn
}
4 changes: 2 additions & 2 deletions example/static_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Future<void> main() async {

// Parse a URL.
// If we don't specify a rule list, PublicSuffix uses DefaultSuffixRules.
var parsedUrl = PublicSuffix.fromString('https://www.komposten.github.io');
var parsedUrl = PublicSuffix(urlString: 'https://www.komposten.github.io');

// Results when matching against both ICANN/IANA and private suffixes.
print(parsedUrl.suffix); // github.io
Expand All @@ -24,7 +24,7 @@ Future<void> main() async {
print(parsedUrl.icannDomain); // github.io

// Punycode decoded results.
parsedUrl = PublicSuffix.fromString('https://www.xn--6qq79v.cn');
parsedUrl = PublicSuffix(urlString: 'https://www.xn--6qq79v.cn');
print(parsedUrl.domain); // xn--6qq79v.cn
print(parsedUrl.punyDecoded.domain); // 你好.cn

Expand Down
23 changes: 11 additions & 12 deletions lib/src/browser/suffix_rules_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class SuffixRulesHelper {
///
/// An [Exception] is thrown if the request fails.
static Future<void> initDefaultListFromUri(Uri uri,
{bool withCredentials,
Map<String, String> requestHeaders,
{bool? withCredentials,
Map<String, String>? requestHeaders,
dynamic sendData,
void Function(ProgressEvent) onProgress}) async {
void Function(ProgressEvent)? onProgress}) async {
DefaultSuffixRules.initFromString(await _getUri(uri,
withCredentials: withCredentials,
requestHeaders: requestHeaders,
Expand All @@ -51,22 +51,22 @@ class SuffixRulesHelper {
///
/// An [Exception] is thrown if the request fails.
static Future<SuffixRules> createListFromUri(Uri uri,
{bool withCredentials,
Map<String, String> requestHeaders,
{bool? withCredentials,
Map<String, String>? requestHeaders,
dynamic sendData,
void Function(ProgressEvent) onProgress}) async {
void Function(ProgressEvent)? onProgress}) async {
return SuffixRules.fromString(await _getUri(uri,
withCredentials: withCredentials,
requestHeaders: requestHeaders,
sendData: sendData,
onProgress: onProgress));
}

static Future<String> _getUri(Uri uri,
{bool withCredentials,
Map<String, String> requestHeaders,
static Future<String?> _getUri(Uri uri,
{bool? withCredentials,
Map<String, String>? requestHeaders,
dynamic sendData,
void Function(ProgressEvent) onProgress}) async {
void Function(ProgressEvent)? onProgress}) async {
try {
var request = await HttpRequest.request(uri.toString(),
withCredentials: withCredentials,
Expand All @@ -77,15 +77,14 @@ class SuffixRulesHelper {
switch (request.status) {
case 200:
return request.responseText;
break;
default:
throw request;
}
} catch (e) {
var object = e;

if (e is ProgressEvent) {
object = e.target;
throw Exception('Request for public suffix list failed: ${e.target}');
}

if (object is HttpRequest) {
Expand Down
14 changes: 7 additions & 7 deletions lib/src/default_suffix_rules.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ import 'package:public_suffix/public_suffix.dart';
///
/// After initialisation the rules can be accessed using [rules].
class DefaultSuffixRules {
static SuffixRules _rules;
static SuffixRules? _rules;

/// Returns the default suffix rules.
///
/// [null] is returned if the list has not been initialised.
static SuffixRules get rules => _rules;
/// `null` is returned if the list has not been initialised.
static SuffixRules? get rules => _rules;

/// Returns the default suffix rules or throws if they haven't
/// been initialised.
static SuffixRules rulesOrThrow() {
if (hasInitialised()) {
return rules;
return rules!;
} else {
throw StateError('PublicSuffixList has not been initialised!');
throw StateError('DefaultSuffixRules has not been initialised!');
}
}

Expand All @@ -40,7 +40,7 @@ class DefaultSuffixRules {
/// Initialises the default rule list from a multi-rule string.
///
/// See [SuffixRules.fromString] for details.
static void initFromString(String rules) {
static void initFromString(String? rules) {
_rules = SuffixRules.fromString(rules);
}

Expand All @@ -60,7 +60,7 @@ class DefaultSuffixRules {

/// Disposes of the default rule list.
///
/// [hasInitialised] will return [false] after this has been called.
/// [hasInitialised] will return `false` after this has been called.
static void dispose() {
_rules = null;
}
Expand Down
1 change: 0 additions & 1 deletion lib/src/io/suffix_rules_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class SuffixRulesHelper {
switch (response.statusCode) {
case 200:
return await response.transform(Utf8Decoder()).join();
break;
default:
throw Exception(
'Request for public suffix list failed: [${response.statusCode}]');
Expand Down
Loading

0 comments on commit aa79805

Please sign in to comment.