diff --git a/lib/cmd_line.dart b/lib/cmd_line.dart index 47409292..f2bba817 100644 --- a/lib/cmd_line.dart +++ b/lib/cmd_line.dart @@ -418,12 +418,12 @@ ResourcesLoader getFileResourceValidator( // GLB-stored buffer return readerResult.buffer; } - if (isNonRelativeUri(uri)) { + if (uri.isNonRelative) { return null; } return fileGuarded(uri).readAsBytes(); }, externalStreamFetch: (uri) { - if (isNonRelativeUri(uri)) { + if (uri.isNonRelative) { return null; } return fileGuarded(uri).openRead(); diff --git a/lib/src/utils.dart b/lib/src/utils.dart index cd5b38d3..3ed01683 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -166,7 +166,7 @@ String getString(Map map, String name, Context context, Uri getUri(String uriString, Context context) { try { final uri = Uri.parse(uriString); - if (isNonRelativeUri(uri)) { + if (uri.isNonRelative) { context .addIssue(SemanticError.nonRelativeUri, name: URI, args: [uriString]); } @@ -727,13 +727,6 @@ bool isTrsDecomposable(Matrix4 matrix) { bool isPot(int value) => (value != 0) && (value & (value - 1) == 0); -bool isNonRelativeUri(Uri uri) => - uri.hasScheme || - uri.hasAuthority || - uri.hasAbsolutePath || - uri.hasQuery || - uri.hasFragment; - int padLength(int length) => length + (-length & 3); List createTypedIntList(int type, int length) { @@ -766,6 +759,11 @@ extension Vector3IsOneOrZero on Vector3 { bool get isZero => x == 0 && y == 0 && z == 0; } +extension IsNonRelativeUri on Uri { + bool get isNonRelative => + hasScheme || hasAuthority || hasAbsolutePath || hasQuery || hasFragment; +} + abstract class ElementChecker { const ElementChecker(); String get path => ''; diff --git a/test/utils.dart b/test/utils.dart index 0a330995..f8312dfb 100644 --- a/test/utils.dart +++ b/test/utils.dart @@ -20,7 +20,7 @@ import 'dart:io'; import 'package:gltf/gltf.dart'; import 'package:gltf/src/errors.dart'; -import 'package:gltf/src/utils.dart' show isNonRelativeUri; +import 'package:gltf/src/utils.dart' show IsNonRelativeUri; import 'package:test/test.dart'; Future compareReports(String basePath) async { @@ -73,7 +73,7 @@ ResourcesLoader _getFileResourceValidator( // GLB-stored buffer return readerResult.buffer; } - if (isNonRelativeUri(uri)) { + if (uri.isNonRelative) { return null; } @@ -83,7 +83,7 @@ ResourcesLoader _getFileResourceValidator( throw GltfExternalResourceNotFoundException(uri.toString()); }); }, externalStreamFetch: (uri) { - if (isNonRelativeUri(uri)) { + if (uri.isNonRelative) { return null; } // TODO: refactor resource loader to remove this diff --git a/web/scripts/validator.dart b/web/scripts/validator.dart index 86fb4aa0..f46dd119 100644 --- a/web/scripts/validator.dart +++ b/web/scripts/validator.dart @@ -27,6 +27,7 @@ import 'dart:math'; import 'dart:typed_data'; import 'package:gltf/gltf.dart'; +import 'package:gltf/src/utils.dart'; const _kChunkSize = 1024 * 1024; const _kMaxReportLength = 512 * 1024; @@ -143,6 +144,9 @@ Future _doValidate(List files) async { final resourcesLoader = ResourcesLoader(context, readerResult.gltf, externalBytesFetch: ([uri]) { if (uri != null) { + if (uri.isNonRelative) { + return null; + } final file = _getFileByUri(files, uri); if (file != null) { return _getFile(file); @@ -154,6 +158,9 @@ Future _doValidate(List files) async { } }, externalStreamFetch: (uri) { if (uri != null) { + if (uri.isNonRelative) { + return null; + } final file = _getFileByUri(files, uri); if (file != null) { return _getFileStream(file);