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

Fix percent progress validation and parsing #5381

Merged
merged 2 commits into from
Sep 3, 2024

Conversation

NighthawkSLO
Copy link
Contributor

@NighthawkSLO NighthawkSLO commented Sep 3, 2024

Description

Current implementation

The progress settings for Set Minimum Progress and Set Maximum Progress have a special validation and parsing function which is too basic and quite broken.

Current implementation of the parser is the regex "(%d+)%%" - digits followed by a literal %, first such match in the string.

Examples of broken parsing

  • -12% parsed as 12
  • 12.34% parsed as 34
  • 12.34 % not parsed
  • abcd 12% efgh parsed as 12
  • 12%34 parsed as 12

New implementation

Find and replace first instance of a literal % with space (See 5th example for why not empty string). The rest of the work is offloaded to tonumber (which trims leading and trailing whitespace)

Find the % at the end of the string with regex "%% *$". If it is found, the parsing is offloaded to tonumber on the substring before the find.

Fixed examples

  • -12% parsed as -12
  • 12.34% parsed as 12.34
  • 12.34 % parsed as 12.34
  • abcd 12% efgh not parsed
  • 12%34 not parsed
  • %12 not parsed
  • 12% abcd not parsed

Type of change

  • Bug fix (non-breaking change which fixes an issue)

WeakAuras/Prototypes.lua Outdated Show resolved Hide resolved
@InfusOnWoW InfusOnWoW merged commit fb285c3 into WeakAuras:main Sep 3, 2024
3 checks passed
@InfusOnWoW
Copy link
Contributor

thanks

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

Successfully merging this pull request may close these issues.

2 participants