Skip to content

Commit

Permalink
[Url Linkifier] Expand to cover www. urls (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpencerLindemuth authored Nov 6, 2020
1 parent 830ed78 commit 503f24a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/src/url.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:linkify/linkify.dart';

final _urlRegex = RegExp(
r'^((?:.|\n)*?)((?:https?):\/\/[^\s/$.?#].[^\s]*)',
r'^((?:.|\n)*?)((?:https?:\/\/|www\.)[^\s/$.?#].[^\s]*)',
caseSensitive: false,
);

Expand All @@ -10,6 +10,11 @@ final _looseUrlRegex = RegExp(
caseSensitive: false,
);

final _protocolIdentifierRegex = RegExp(
r'^(https?:\/\/)',
caseSensitive: false
);

class UrlLinkifier extends Linkifier {
const UrlLinkifier();

Expand Down Expand Up @@ -48,7 +53,7 @@ class UrlLinkifier extends Linkifier {

var url = originalUrl;

if (loose) {
if (loose || !originalUrl.startsWith(_protocolIdentifierRegex)) {
originalUrl =
(options.defaultToHttps ?? false ? "https://" : "http://") +
originalUrl;
Expand Down

0 comments on commit 503f24a

Please sign in to comment.