Skip to content

Commit

Permalink
Merge pull request #385 from stephenegriffin/text
Browse files Browse the repository at this point in the history
direct assign untrusted text with setText
  • Loading branch information
stephenegriffin committed Jun 16, 2020
2 parents ecf8d5b + 735ba25 commit f4b5d4e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Binary file modified UnitTest/SmartViewTestData/Out/12-propdef-out5.dat
Binary file not shown.
14 changes: 9 additions & 5 deletions UnitTest/tests/blocktest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ namespace blocktest
Assert::AreEqual(block1->getText(), std::wstring(L"test"));
Assert::AreEqual(block1->getChildren().empty(), true);
Assert::AreEqual(block1->toString(), std::wstring(L"test"));
Assert::AreEqual(block1->getSize(), size_t(5));
Assert::AreEqual(block1->getOffset(), size_t(6));
Assert::AreEqual(block1->getSource(), ULONG(7));
Assert::AreEqual(block1->getSize(), size_t{5});
Assert::AreEqual(block1->getOffset(), size_t{6});
Assert::AreEqual(block1->getSource(), ULONG{7});

block1->setText(L"the %1!ws!", L"other");
Assert::AreEqual(block1->getText(), std::wstring(L"the other"));
Expand All @@ -42,6 +42,10 @@ namespace blocktest
block1->setText(L"hello");
Assert::AreEqual(block1->getText(), std::wstring(L"hello"));

// Text with % and no arguments should go straight in
block1->setText(L"%d %ws %");
Assert::AreEqual(block1->getText(), std::wstring(L"%d %ws %"));

block1->setText(L"hello %1!ws!", L"world");
Assert::AreEqual(block1->getText(), std::wstring(L"hello world"));

Expand All @@ -58,8 +62,8 @@ namespace blocktest
block3->addChild(block1);
Assert::AreEqual(block3->hasData(), true);
block3->setSource(42);
Assert::AreEqual(block3->getSource(), ULONG(42));
Assert::AreEqual(block1->getSource(), ULONG(42));
Assert::AreEqual(block3->getSource(), ULONG{42});
Assert::AreEqual(block1->getSource(), ULONG{42});
}

TEST_METHOD(Test_blockStringA)
Expand Down
1 change: 1 addition & 0 deletions core/smartview/block/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace smartview
{
text = strings::formatmessage(_text.c_str(), args...);
}
void setText(const std::wstring& _text) { text = _text.c_str(); }

const std::vector<std::shared_ptr<block>>& getChildren() const noexcept { return children; }
size_t getSize() const noexcept { return cb; }
Expand Down

0 comments on commit f4b5d4e

Please sign in to comment.