Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ void main() {
Uri.parse('https://example.com/a/b/c/version.json?cachebuster=1'),
);
expect(
// 'c' here is to be considered as a page, not a folder
plugin.versionJsonUrl(
'https://example.com/a/b/c?hello_world=true#/my-page', 1),
Uri.parse('https://example.com/a/b/c/version.json?cachebuster=1'),
Uri.parse('https://example.com/a/b/version.json?cachebuster=1'),
);
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,28 @@ class PackageInfoPlusWebPlugin extends PackageInfoPlatform {
Uri versionJsonUrl(String baseUrl, int cacheBuster) {
final baseUri = Uri.parse(baseUrl);
final regExp = RegExp(r'[^/]+\.html.*');
final originPath =
final String originPath =
'${baseUri._origin}${baseUri.path.replaceAll(regExp, '')}';
final versionJson = 'version.json?cachebuster=$cacheBuster';
return Uri.parse(originPath.endsWith('/')
? '$originPath$versionJson'
: '$originPath/$versionJson');

// Clean uri: remove fragment and query
Uri uri = Uri.parse(originPath).removeFragment().replace(query: '');

// In http/s, if the last part has no file extension and not trailing slash,
// we can safely remove it since it's not considered as a folder
if (uri.path.length > 1 &&
!uri.path.endsWith('/') &&
(uri.isScheme('http') || uri.isScheme('https'))) {
uri = uri.replace(path: uri.path.substring(0, uri.path.lastIndexOf('/')));
}

// Clean uri: remove empty path segments
final List<String> segments = [...uri.pathSegments]
..removeWhere((element) => element == '');

// Add file and cachebuster query
return uri.replace(
query: 'cachebuster=$cacheBuster',
pathSegments: [...segments, 'version.json']);
}

@override
Expand Down