Skip to content

Commit

Permalink
fix string multiplication bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Prevter committed Dec 15, 2024
1 parent 8bd1766 commit a9323e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,11 @@ namespace rift {
}

auto const& str = isString() ? getString() : other.getString();
auto const& num = isString() ? other.toInteger() : toInteger();
auto num = isString() ? other.toInteger() : toInteger();

if (num <= 0) {
return geode::Ok(Value(""));
}

std::string result;
result.reserve(str.size() * num);
Expand Down
1 change: 1 addition & 0 deletions test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ int main() {
RIFT_EVAL("('hello world' - 'hello ')[2] == 'r'", true); // string subtraction
RIFT_TEST("{middlePad('#' * (progress * 4 / 10), 40, '-')} {progress}%", "----------####################---------- 50%", {{"progress", 50}});
RIFT_TEST("{min(20, 40)}", "20");
RIFT_EVAL("-1 * 'hello'", ""); // making sure string multiplication with negative number is empty

fmt::println("\nResults:\nTests passed: {}/{}\nTests failed: {}/{}", TEST_PASSED, TEST_COUNT, TEST_FAILED, TEST_COUNT);
return TEST_FAILED;
Expand Down

0 comments on commit a9323e3

Please sign in to comment.