Skip to content
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

runOnNewVersion saves version numbers with non-numerical values and does not sanitize them upon retrieval #24

Closed
Camerash opened this issue Nov 2, 2023 · 3 comments
Assignees

Comments

@Camerash
Copy link

Camerash commented Nov 2, 2023

In version 1.5.4 the logic for version number retrieval in runOnNewVersion is:

final savedVersion = preferences.getString(onceKey) ?? '';
String existingVersion = currentVersion.replaceAll(RegExp(r'[^\d]+'), '');

Where as in 1.5.3 it looks like:

final savedVersion = preferences.getString(onceKey)!.replaceAll(".", "");
String existingVersion = currentVersion.replaceAll(".", "");

In the newer version 1.5.4 the sanitation for removing non-numerical in savedVersion is removed.

However within runOnNewVersion the library is saving also non-sanitized version number to SharedPreference:

String currentVersion = packageInfo.version;
/// ...
/// ...
/// ...
preferences.setString(onceKey, currentVersion);

Therefore on version check it will still throw error:

flutter: FormatException: 2.3.4
flutter: 
#0      num.parse (dart:core/num.dart:574:5)
#1      OnceRunner.runOnNewVersion (package:once/src/runner/runner.dart:166:44)
<asynchronous suspension>

I suggest sanitizing savedVersion variable with the same logic as that of existingVersion, this will also ensure value saved using previous version of once will decode version information correctly.

System Info:

flutter: 3.13.6
once: 1.5.4
package_info_plus: 4.1.0

@Camerash Camerash changed the title runOnNewVersion saves version numbers with non-numerical values and does not remove them upon retrieval runOnNewVersion saves version numbers with non-numerical values and does not sanitize them upon retrieval Nov 2, 2023
@Camerash
Copy link
Author

Camerash commented Nov 2, 2023

Please let me know if this issue is valid, and if yes I can help contribute and put a PR up. Thanks!

@MostafaSolimanMO MostafaSolimanMO self-assigned this Nov 6, 2023
@MostafaSolimanMO
Copy link
Owner

Thank you so much for this, Esmond.
Yes, it's valid. I've fixed it and I'm publishing a new release

@MostafaSolimanMO
Copy link
Owner

Fixed on 1.6.0.
Thanks @Camerash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants