Skip to content

[Bug]: Wrong version.json path when path contains non-word characters #1891

Description

@fhuonder

Platform

Web

Plugin

package_info_plus

Version

4.0.2

Flutter SDK

3.10.3

Steps to reproduce

Have a Flutter web app with hostElement and have the app embedded in a site of which the name contains a non-word character.
e.g. my-super-file.html ("-" is not a word).
The plugin tries to download the file then from https://www.base.url/my-super-version.json

The problem is the regex https://github.com/fluttercommunity/plus_plugins/blame/ab41d1ac0236e2456686d0c16b9abc17294c08e7/packages/package_info_plus/package_info_plus/lib/src/package_info_plus_web.dart#L24 here.

The regex should be someting like: RegExp(r'[^/]+\.html.*')

Would be great if you could provide a fix.

Regards,
Florian

Code Sample

void main() {
  final baseUrl = "https://www.my-site.com/my-super-page.html#/";
  final cacheBuster = 1234;
  final baseUri = Uri.parse(baseUrl);
  //final regExp = RegExp(r'\w+\.html.*'); //original: does not work
  final regExp = RegExp(r'[^/]+.html.*'); //fix: does work
  final originPath = '${baseUri.origin}${baseUri.path.replaceAll(regExp, '')}';
  final versionJson = 'version.json?cachebuster=$cacheBuster';
  print("baseUriPath: ${baseUri.path.replaceAll(regExp, '')}");
  print(Uri.parse(originPath.endsWith('/')
      ? '$originPath$versionJson'
      : '$originPath/$versionJson'));
}

Logs

html_dart2js.dart:18592     GET https://www.my-page.com/my-super-/version.json?cachebuster=1685985905158 403

Flutter Doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.3, on Ubuntu 20.04.5 LTS 5.15.90.1-microsoft-standard-WSL2, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✗] Linux toolchain - develop for Linux desktop
    ✗ clang++ is required for Linux development.
      It is likely available from your distribution (e.g.: apt install clang), or can be downloaded from https://releases.llvm.org/
    ✗ CMake is required for Linux development.
      It is likely available from your distribution (e.g.: apt install cmake), or can be downloaded from https://cmake.org/download/
    ✗ ninja is required for Linux development.
      It is likely available from your distribution (e.g.: apt install ninja-build), or can be downloaded from https://github.com/ninja-build/ninja/releases
    ✗ pkg-config is required for Linux development.
      It is likely available from your distribution (e.g.: apt install pkg-config), or can be downloaded from https://www.freedesktop.org/wiki/Software/pkg-config/
[!] Android Studio (not installed)
[✓] Connected device (1 available)
[✓] Network resources

Checklist before submitting a bug

  • I Google'd a solution and I couldn't find it
  • I searched on StackOverflow for a solution and I couldn't find it
  • I read the README.md file of the plugin
  • I'm using the latest version of the plugin
  • All dependencies are up to date with flutter pub upgrade
  • I did a flutter clean
  • I tried running the example project

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions