You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OS Version: Ubuntu 24.04
rviz version: ros2 jazzy
Compiler name and version number: Ubuntu clang version 18.1.3
Source or binary build?
source build
build options: --mixin asan-gcc
Description
The function rviz_rendering::string_helper::splitStringIntoTrimmedItems drops empty tokens when splitting a string, particularly in cases involving consecutive delimiters or trailing delimiters. This behavior deviates from standard string splitting expectations (e.g., std::getline in C++ or str.split in Python), which typically retain empty tokens, and may lead to data loss or incorrect processing.
This issue was discovered during an extreme input test where a string of 1,000,000 'a' characters was split by the 'a' character. The expected result was a vector of 1,000,001 empty strings, but the actual result was an empty vector, indicating that all empty tokens were silently discarded.
Test Case
#include<string>
#include<vector>
#include"gtest/gtest.h"
#include"gmock/gmock.h"
#include"../../src/rviz_rendering/string_helper.cpp"// NOLINT (build/include)usingnamespace ::testing;// NOLINTTEST(String_Helper__Test, split_string_extreme_large_input) {
std::string test_string(1000000, 'a'); // Creating a large input string
std::vector<std::string> actual;
ASSERT_NO_THROW(actual = rviz_rendering::string_helper::splitStringIntoTrimmedItems(
test_string, 'a'));
ASSERT_EQ(actual.size(), 1000001); // Checking correct handling of large string
}
Output
Running main() from gmock_main.cc
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from String_Helper__Test
[ RUN ] String_Helper__Test.split_string_extreme_large_input
/home/shangzh/ros2_jazzy/src/ros2/rviz/rviz_rendering/test/rviz_rendering/string_helper_test.cpp:13: Failure
Expected equality of these values:
actual.size()
Which is: 0
1000001
[ FAILED ] String_Helper__Test.split_string_extreme_large_input (275 ms)
[----------] 1 test from String_Helper__Test (275 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (275 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] String_Helper__Test.split_string_extreme_large_input
1 FAILED TEST
Expected behavior
Given the following input:
std::string test_string(1000000, 'a');
auto result = splitStringIntoTrimmedItems(test_string, 'a');
The expected result is a vector of 1,000,001 empty strings, consistent with the behavior of standard split functions.
Actual behavior
The returned result is an empty vector:
result.size() == 0
All split tokens, which are empty strings in this case, are filtered out without warning. This behavior is not documented and is likely to be surprising to users.
Additional information
Suggested Fix
We recommend one or more of the following improvements:
1.Adjust the behavior: Remove the filtering condition so that empty tokens are preserved.
2.Add a configurable parameter: Introduce a boolean parameter such as keep_empty = true to give users control over whether to retain empty tokens.
3.Improve documentation: If the current behavior is intentional, update the function documentation to clearly state that empty strings will be discarded.
The text was updated successfully, but these errors were encountered:
Operating System:
Linux shangzh-VMware-Virtual-Platform 6.11.0-21-generic #21~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Feb 24 16:52:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
ROS version or commit hash:
ros2 jazzy
RMW implementation (if applicable):
No response
RMW Configuration (if applicable):
No response
Client library (if applicable):
rviz
'ros2 doctor --report' output
ros2 doc --report
Steps to reproduce issue
Environment
OS Version: Ubuntu 24.04
rviz version: ros2 jazzy
Compiler name and version number: Ubuntu clang version 18.1.3
Source or binary build?
source build
build options: --mixin asan-gcc
Description
The function rviz_rendering::string_helper::splitStringIntoTrimmedItems drops empty tokens when splitting a string, particularly in cases involving consecutive delimiters or trailing delimiters. This behavior deviates from standard string splitting expectations (e.g., std::getline in C++ or str.split in Python), which typically retain empty tokens, and may lead to data loss or incorrect processing.
This issue was discovered during an extreme input test where a string of 1,000,000 'a' characters was split by the 'a' character. The expected result was a vector of 1,000,001 empty strings, but the actual result was an empty vector, indicating that all empty tokens were silently discarded.
Test Case
Output
Expected behavior
Given the following input:
The expected result is a vector of 1,000,001 empty strings, consistent with the behavior of standard split functions.
Actual behavior
The returned result is an empty vector:
result.size() == 0
All split tokens, which are empty strings in this case, are filtered out without warning. This behavior is not documented and is likely to be surprising to users.
Additional information
Suggested Fix
We recommend one or more of the following improvements:
1.Adjust the behavior: Remove the filtering condition so that empty tokens are preserved.
// Remove `if (!item.empty())` check filenames.push_back(item);
2.Add a configurable parameter: Introduce a boolean parameter such as keep_empty = true to give users control over whether to retain empty tokens.
3.Improve documentation: If the current behavior is intentional, update the function documentation to clearly state that empty strings will be discarded.
The text was updated successfully, but these errors were encountered: