Skip to content

Commit

Permalink
fix(package_info_plus): remove html file parts from version url (#1330)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Koch <koch@lotum.de>
Co-authored-by: Gabriel Terwesten <gabriel@terwesten.net>
  • Loading branch information
3 people authored Apr 25, 2023
1 parent ce7c956 commit cc13fc6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/scripts/integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ fi

if [ "$ACTION" == "web" ]
then
melos bootstrap --scope="$SCOPE"

# Start x virtual framebuffer for chrome to run.
export DISPLAY=:99
Xvfb $DISPLAY -screen 0 1024x768x16 &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,37 @@ void main() {
},
);

testWidgets(
'Get correct versionJsonUrl for urls to html files',
(tester) async {
expect(
plugin.versionJsonUrl('https://example.com', 1),
Uri.parse('https://example.com/version.json?cachebuster=1'),
);
expect(
plugin.versionJsonUrl('https://example.com/', 1),
Uri.parse('https://example.com/version.json?cachebuster=1'),
);
expect(
plugin.versionJsonUrl('https://example.com/index.html', 1),
Uri.parse('https://example.com/version.json?cachebuster=1'),
);
expect(
plugin.versionJsonUrl('https://example.com/index.html#/my-page', 1),
Uri.parse('https://example.com/version.json?cachebuster=1'),
);
expect(
plugin.versionJsonUrl(
'https://example.com/index.html?hello_world=true/#/my-page', 1),
Uri.parse('https://example.com/version.json?cachebuster=1'),
);
expect(
plugin.versionJsonUrl('https://example.com/a/b/c/wrapper.html', 1),
Uri.parse('https://example.com/a/b/c/version.json?cachebuster=1'),
);
},
);

testWidgets('Get correct versionJsonUrl for chrome-extension',
(tester) async {
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class PackageInfoPlusWebPlugin extends PackageInfoPlatform {
/// Get version.json full url.
Uri versionJsonUrl(String baseUrl, int cacheBuster) {
final baseUri = Uri.parse(baseUrl);
final originPath = '${baseUri._origin}${baseUri.path}';
final regExp = RegExp(r'\w+\.html.*');
final originPath =
'${baseUri._origin}${baseUri.path.replaceAll(regExp, '')}';
final versionJson = 'version.json?cachebuster=$cacheBuster';
return Uri.parse(originPath.endsWith('/')
? '$originPath$versionJson'
Expand Down

0 comments on commit cc13fc6

Please sign in to comment.