Skip to content

Commit 5a74d8a

Browse files
authored
Properly handle Windows file: URLs on Node.js (#30098)
This adds logic to the JS implementation of URI to determine whether the code is running on Windows under Node.js.
1 parent a786576 commit 5a74d8a

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
the system level timeout duration, a timeout may occur sooner than specified
2828
in 'timeout'.
2929

30+
* `dart:core`
31+
* The `Uri` class now correctly handles paths while running on Node.js on
32+
Windows.
33+
3034
### Dart VM
3135
* Support for MIPS has been remvoed.
3236

pkg/dev_compiler/tool/input_sdk/patch/core_patch.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,13 @@ class Uri {
602602
@patch
603603
class _Uri {
604604
@patch
605-
static bool get _isWindows => false;
605+
static bool get _isWindows => _isWindowsCached;
606+
607+
static final bool _isWindowsCached = JS(
608+
'bool',
609+
'typeof process != "undefined" && '
610+
'Object.prototype.toString.call(process) == "[object process]" && '
611+
'process.platform == "win32"');
606612

607613
// Matches a String that _uriEncodes to itself regardless of the kind of
608614
// component. This corresponds to [_unreservedTable], i.e. characters that

sdk/lib/_internal/js_runtime/lib/core_patch.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,13 @@ class Uri {
611611
@patch
612612
class _Uri {
613613
@patch
614-
static bool get _isWindows => false;
614+
static bool get _isWindows => _isWindowsCached;
615+
616+
static final bool _isWindowsCached = JS(
617+
'bool',
618+
'typeof process != "undefined" && '
619+
'Object.prototype.toString.call(process) == "[object process]" && '
620+
'process.platform == "win32"');
615621

616622
// Matches a String that _uriEncodes to itself regardless of the kind of
617623
// component. This corresponds to [_unreservedTable], i.e. characters that

0 commit comments

Comments
 (0)