-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
CompilationUnit.directive.stringValue Strips Path Separators on Windows #59629
Comments
I don't know why it would be behaving differently under Windows, but it shouldn't be, so there's definitely a bug. But there might also be an incorrect expectation. When you execute |
(Side note: also interesting to get the literal string content as the string can be a concatenation of adjacent strings. E.g. this is legal: |
@BenAuerDev thanks for the detailed report. Is there a way to get a minimal reproduction case? I'd basically like to see "Here's the Dart source with an import with a slash in it" and "Here's what |
Ah 💪 That would make my use case even easier if the returned value is the same on windows and linux |
@srawlins Unfortunately I don't have access to a windows machine currently. I only came across it when running a test at I can see if I'll be able to set up a VM with windows and try it there, or maybe borrow a windows machine when I'm visiting family over the holidays 💪 |
Hello @srawlins, I managed to get a minimal reproduction case, I tested it via the serverpod pipeline: test(
'CompilationUnit.directives[i].uri.stringValue returns relative path without separators on Windows.',
() {
var content = Platform.isWindows
? "part 'sub_dir\\example_child.dart';"
: "part 'sub_dir/example_child.dart';";
var unit = parseString(content: content).unit;
var directive = unit.directives.whereType<PartDirective>().first;
var directiveStringValue = directive.uri.stringValue;
var expectedPath = Platform.isWindows
? 'sub_direxample_child.dart'
: 'sub_dir/example_child.dart';
expect(directiveStringValue == expectedPath, isTrue);
}); |
CompilationUnit.directives.uri.stringValue
behaves inconsistently across platforms. On Windows, path separators inpart
andpart of
directives are stripped, whereas on Linux, they are preserved.Current Behavior
For the following directives in Dart code:
Linux Output:
../filename.dart
andsub_dir/filename.dart
Windows Output:
..filename.dart
andsub_dirfilename.dart
Expected Behavior
For the above directives:
Linux Output (unchanged):
../filename.dart
andsub_dir/filename.dart
Windows Output:
..\filename.dart
andsub_dir\filename.dart
sdk version
: '>=3.3.0 <4.0.0'analyzer
: '^6.0.0'Related Work:
I encountered this while I was working on a PR at serverpod where I tested generated code using
CompilationUnit
and comparingCompilationUnit.directives.uri.stringValue
to the expected path.This test worked fine on Linux but failed on Windows due to the inconsistency.
Log of the directives of the
CompilationUnit
in windows:Log of
directive.uri.stringValue
on windows:Log of
directive.uri.stringValue
on Linux:If I can help with any further information, you can holla at me any time 💪
The text was updated successfully, but these errors were encountered: