Remove trailing null char from IOOverrides.fseGetType
This null char is inserted by _toNullTerminatedUtf8Array, and right
below that function is _toStringFromUtf8Array, which does the opposite.
But _toStringFromUtf8Array is currently dead code, so it looks like the
intent was always to use _toStringFromUtf8Array for this, and the fact
that utf8.decode was being used instead is just a mistake.
Bug: https://github.com/dart-lang/sdk/issues/34885
Change-Id: I1404c7783b055902b256176aa61971c0d6969f5e
Fixes: https://github.com/dart-lang/sdk/issues/34885
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/243103
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Liam Appelbe <liama@google.com>
diff --git a/sdk/lib/io/file_system_entity.dart b/sdk/lib/io/file_system_entity.dart
index 573457d..0b9ae80 100644
--- a/sdk/lib/io/file_system_entity.dart
+++ b/sdk/lib/io/file_system_entity.dart
@@ -792,7 +792,7 @@
return _getTypeSyncHelper(rawPath, followLinks);
}
return overrides.fseGetTypeSync(
- utf8.decode(rawPath, allowMalformed: true), followLinks);
+ _toStringFromUtf8Array(rawPath), followLinks);
}
static Future<FileSystemEntityType> _getTypeRequest(
@@ -813,8 +813,7 @@
if (overrides == null) {
return _getTypeRequest(rawPath, followLinks);
}
- return overrides.fseGetType(
- utf8.decode(rawPath, allowMalformed: true), followLinks);
+ return overrides.fseGetType(_toStringFromUtf8Array(rawPath), followLinks);
}
static _throwIfError(Object result, String msg, [String? path]) {
diff --git a/tests/standalone/io/regress_34885_test.dart b/tests/standalone/io/regress_34885_test.dart
new file mode 100644
index 0000000..dadf8f0
--- /dev/null
+++ b/tests/standalone/io/regress_34885_test.dart
@@ -0,0 +1,37 @@
+// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+import 'dart:convert';
+import 'dart:io';
+import 'dart:typed_data';
+
+import "package:async_helper/async_helper.dart";
+import "package:expect/expect.dart";
+
+class FileSystemEntityMock {
+ static Future<FileSystemEntityType> getType(String path, bool followLinks) {
+ Expect.equals(path.length, 4);
+ return new Future.value(FileSystemEntityType.file);
+ }
+
+ static FileSystemEntityType getTypeSync(String path, bool followLinks) {
+ Expect.equals(path.length, 4);
+ return FileSystemEntityType.file;
+ }
+}
+
+main() async {
+ Future<Null> f = IOOverrides.runZoned(
+ () async {
+ Expect.equals(
+ await FileSystemEntity.type("file"), FileSystemEntityType.file);
+ Expect.equals(
+ FileSystemEntity.typeSync("file"), FileSystemEntityType.file);
+ },
+ fseGetType: FileSystemEntityMock.getType,
+ fseGetTypeSync: FileSystemEntityMock.getTypeSync,
+ );
+ await f;
+}
diff --git a/tests/standalone_2/io/regress_34885_test.dart b/tests/standalone_2/io/regress_34885_test.dart
new file mode 100644
index 0000000..dadf8f0
--- /dev/null
+++ b/tests/standalone_2/io/regress_34885_test.dart
@@ -0,0 +1,37 @@
+// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+import 'dart:convert';
+import 'dart:io';
+import 'dart:typed_data';
+
+import "package:async_helper/async_helper.dart";
+import "package:expect/expect.dart";
+
+class FileSystemEntityMock {
+ static Future<FileSystemEntityType> getType(String path, bool followLinks) {
+ Expect.equals(path.length, 4);
+ return new Future.value(FileSystemEntityType.file);
+ }
+
+ static FileSystemEntityType getTypeSync(String path, bool followLinks) {
+ Expect.equals(path.length, 4);
+ return FileSystemEntityType.file;
+ }
+}
+
+main() async {
+ Future<Null> f = IOOverrides.runZoned(
+ () async {
+ Expect.equals(
+ await FileSystemEntity.type("file"), FileSystemEntityType.file);
+ Expect.equals(
+ FileSystemEntity.typeSync("file"), FileSystemEntityType.file);
+ },
+ fseGetType: FileSystemEntityMock.getType,
+ fseGetTypeSync: FileSystemEntityMock.getTypeSync,
+ );
+ await f;
+}