Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip IO errors in web frontend on non-relative URIs #233

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/cmd_line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 6 additions & 8 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ String getString(Map<String, Object> 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]);
}
Expand Down Expand Up @@ -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<int> createTypedIntList(int type, int length) {
Expand Down Expand Up @@ -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<T extends num> {
const ElementChecker();
String get path => '';
Expand Down
6 changes: 3 additions & 3 deletions test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -73,7 +73,7 @@ ResourcesLoader _getFileResourceValidator(
// GLB-stored buffer
return readerResult.buffer;
}
if (isNonRelativeUri(uri)) {
if (uri.isNonRelative) {
return null;
}

Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions web/scripts/validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -143,6 +144,9 @@ Future<ValidationResult> _doValidate(List<File> 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);
Expand All @@ -154,6 +158,9 @@ Future<ValidationResult> _doValidate(List<File> files) async {
}
}, externalStreamFetch: (uri) {
if (uri != null) {
if (uri.isNonRelative) {
return null;
}
final file = _getFileByUri(files, uri);
if (file != null) {
return _getFileStream(file);
Expand Down
Loading