Skip to content

Commit

Permalink
string: fix isNumber accepting - as valid number
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Jun 15, 2024
1 parent 8e10e06 commit ea8fd1d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/string/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool Hyprutils::String::isNumber(const std::string& str, bool allowfloat) {
}
}

if (str.back() == '.')
if (!isdigit(str.back()))
return false;

return true;
Expand Down
1 change: 1 addition & 0 deletions tests/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ int main(int argc, char** argv, char** envp) {
EXPECT(isNumber("---3423--432s"), false);
EXPECT(isNumber("1s"), false);
EXPECT(isNumber(""), false);
EXPECT(isNumber("-"), false);
EXPECT(isNumber("--0"), false);
EXPECT(isNumber("abc"), false);
EXPECT(isNumber("0.0", true), true);
Expand Down

0 comments on commit ea8fd1d

Please sign in to comment.