refactor uri scheme validation
This commit is contained in:
@@ -17,6 +17,11 @@
|
|||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const _supportedSchemes = {'https', 'http', 'ftp', 'file', 'content', 'about'};
|
||||||
|
|
||||||
extension UriX on Uri {
|
extension UriX on Uri {
|
||||||
Uri get base => Uri.parse('$scheme://$authority');
|
Uri get base => Uri.parse('$scheme://$authority');
|
||||||
|
|
||||||
|
bool get hasSupportedScheme => _supportedSchemes.contains(scheme);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,9 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import 'package:universal_io/io.dart';
|
import 'package:universal_io/io.dart';
|
||||||
|
import 'package:weblibre/extensions/uri.dart';
|
||||||
|
|
||||||
final _domainRegex = RegExp(r'\.[a-zA-Z]{2,}$');
|
final _domainRegex = RegExp(r'\.[a-zA-Z]{2,}$');
|
||||||
const _supportedSchemes = {'https', 'http', 'ftp', 'file', 'content', 'about'};
|
|
||||||
|
|
||||||
Uri? tryParseUrl(String? input, {bool eagerParsing = false}) {
|
Uri? tryParseUrl(String? input, {bool eagerParsing = false}) {
|
||||||
if (input != null) {
|
if (input != null) {
|
||||||
@@ -42,7 +42,7 @@ Uri? tryParseUrl(String? input, {bool eagerParsing = false}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (uri.authority.isNotEmpty) {
|
if (uri.authority.isNotEmpty) {
|
||||||
if (_supportedSchemes.contains(uri.scheme) || !uri.hasScheme) {
|
if (uri.hasSupportedScheme || !uri.hasScheme) {
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user