Disable comment char in ArrayConverter list parsing#427
Conversation
parseElements left StreamTokenizer's default comment character '/' active, so a list element containing a slash commented out the rest of the input and dropped the following elements. Treat '/' as an ordinary separator instead.
There was a problem hiding this comment.
Pull request overview
This pull request fixes ArrayConverter.parseElements treating / as a comment introducer during StreamTokenizer parsing, which could silently drop later elements when list items contain forward slashes.
Changes:
- Disable
/as a comment character inStreamTokenizersetup so it behaves like other non-allowed separator characters. - Add a regression test ensuring forward slashes split tokens rather than truncating input.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/main/java/org/apache/commons/beanutils2/converters/ArrayConverter.java | Configures StreamTokenizer to treat / as an ordinary character instead of a comment start during element parsing. |
| src/test/java/org/apache/commons/beanutils2/converters/ArrayConverterTest.java | Adds a unit test covering forward-slash behavior in delimited list parsing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@rootvector2 Please address #426 (comment) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| final String[] result = converter.convert(String[].class, value); | ||
| assertNotNull(result, "result.null"); | ||
| assertEquals(4, result.length, "result.length"); | ||
| assertEquals("first", result[0], "result[0]"); |
There was a problem hiding this comment.
Are you sure?
The / now behaves the same as a ,? That can't be right. Shouldn't the asserts be:
assertEquals("first/value", result[0]);
assertEquals("second/value", result[1]);?
There was a problem hiding this comment.
Yes. Any non-allowed char splits and keeps both sides by default, same as _ in testUnderscore_BEANUTILS_302 (first_value,second_value parses to 4 elements). Before the patch / was the only char that instead commented out the rest of the input, so a/b,c parsed to just ["a"]. Your asserts hold once / is in the allowed chars, same as _. I extended the test to mirror the underscore test: 4 elements by default, ["first/value", "second/value"] after setAllowedChars(new char[] { '.', '-', '/' }).
garydgregory
left a comment
There was a problem hiding this comment.
@rootvector2 Please see my questions.
|
Done on #426, switched the test to |
ArrayConverter.parseElementssets up aStreamTokenizerbut never disables its default comment character/, so a list element containing a slash comments out the rest of the input and the following elements are silently dropped:a/b,cparses to["a"]and a leading slash such as/etc/passwd,/tmp/xparses to an empty array. Every other non-allowed character splits and keeps both sides (seetestUnderscore_BEANUTILS_302, wherefirst_value,second_valueyields four elements), so/is the outlier.st.ordinaryChar('/')makes it split like any other separator; adding/toallowedCharsstill keeps it inside a token. Found while auditing the delimited-list parser against the_behavior that test pins.mvn; that'smvnon the command line by itself.