android-version-actions icon indicating copy to clipboard operation
android-version-actions copied to clipboard

Regex matches versionCode in comments

Open tibbe opened this issue 2 years ago • 2 comments

I was scratching my head why this action wasn't working for me. After some debugging I realized that it had managed to replace versionCode in a comment (e.g. // Here's a sentence with versionCode in it). The replacement mechanism needs to be a bit more robust. At the very least a regex that doesn't match on a comment line.

tibbe avatar Jun 06 '22 13:06 tibbe

The version code should be an integer so you can at least use \d+ to get somewhat better matching.

tibbe avatar Jun 06 '22 13:06 tibbe

One idea would be to make sure the line start with whitespace:

const versionCodeRegexPattern = /^(\s*versionCode(?:\s|=)\s*)(\d+.*)/;

This doesn't match (single line) comments and only integer versionCodes (which they should be according to the docs).

This assume there is actually a code in build.gradle but so did the previous version.

tibbe avatar Jun 06 '22 14:06 tibbe