Skip to content

Commit

Permalink
Fix a bug with detecting the base path for DevTools assets (#8826)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzieschmoll authored Jan 30, 2025
1 parent c00e7e9 commit 13926a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/devtools_app/lib/src/shared/primitives/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1114,10 +1114,13 @@ Map<K, R> subtractMaps<K, F, S, R>({
/// ==> 'http://127.0.0.1:61962/mb9Sw4gCYvU=/devtools'
/// * 'http://127.0.0.1:61962/performance' ==> 'http://127.0.0.1:61962'
String devtoolsAssetsBasePath({required String origin, required String path}) {
// Ensure that we are truly only using the origin of the URI String passed as
// the [origin] parameter.
final trimmedOrigin = Uri.parse(origin).origin;
const separator = '/';
final pathParts = path.split(separator);
// The last path part is the DevTools page (e.g. 'performance' or 'snapshot'),
// which is not part of the hosted asset path.
pathParts.removeLast();
return '$origin${pathParts.join(separator)}';
return '$trimmedOrigin${pathParts.join(separator)}';
}
16 changes: 16 additions & 0 deletions packages/devtools_app/test/shared/primitives/utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,22 @@ void main() {
),
equals('http://127.0.0.1:61962'),
);
// This is how a DevTools url will be structured when DevTools is ran
// locally using `dt run`.
expect(
devtoolsAssetsBasePath(origin: 'http://127.0.0.1:9100/', path: '/home'),
equals('http://127.0.0.1:9100'),
);
// This is how a DevTools url will be structured when it has query
// parameters (e.g. when it is connected to an app).
expect(
devtoolsAssetsBasePath(
origin:
'http://127.0.0.1:9100/home?uri=ws://127.0.0.1:50416/Hnr3zwp99d0=/ws',
path: '/home',
),
equals('http://127.0.0.1:9100'),
);
});
}

Expand Down

0 comments on commit 13926a9

Please sign in to comment.