[
https://issues.apache.org/jira/browse/KARAF-7678?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17701617#comment-17701617
]
ASF GitHub Bot commented on KARAF-7678:
---------------------------------------
CMoH commented on code in PR #1716:
URL: https://github.com/apache/karaf/pull/1716#discussion_r1140019185
##########
shell/core/src/main/java/org/apache/karaf/shell/support/table/Col.java:
##########
@@ -148,8 +149,14 @@ String format(Object cellData) {
if (fullContent.length() == 0) {
return "";
}
- String finalContent = cut(fullContent,
getClippedSize(fullContent.length()));
- updateSize(finalContent.length());
+ if (wrap && size < fullContent.length()) {
+ // make sure splitLines will have an estimate cell size if wrap is
true
+ updateSize(fullContent.length());
+ }
+ List<String> lines = splitLines(fullContent);
+ int maxLineSize =
lines.stream().mapToInt(String::length).max().getAsInt(); // at least one line
exists due to test above
+ updateSize(maxLineSize); // calls getClippedSize()
+ String finalContent = lines.stream().map(line -> cut(line,
getClippedSize(line.length()))).collect(Collectors.joining("\n"));
Review Comment:
I think in this particular case I think it will work, since `\n` is included
in the Windows line separator, `\n\r`. Also, the contents of `splitLines()` is
the verbatim top-section of the `getContents()` method, so at least I don't
expect the behaviour to change after this commit.
However, the comment is valid in principle. As you mentioned in
https://github.com/apache/karaf/pull/1715#discussion_r1139063272, this seems to
be a style issue across the entire code base. If so, would it be worth
adressing them all as a separate issue?
> ShellTable erroneously clips out text from multi-line column contents
> ---------------------------------------------------------------------
>
> Key: KARAF-7678
> URL: https://issues.apache.org/jira/browse/KARAF-7678
> Project: Karaf
> Issue Type: Bug
> Components: karaf
> Affects Versions: 4.4.3
> Reporter: Ciprian Ciubotariu
> Priority: Minor
>
> The {{ShellTable}} implementation clips column contents to the column's
> {{maxSize}} before inspecting if the contents is sigle or multi-line. This
> idea works well with single-line row contents, but it is faulty if the column
> text contains newlines.
> Given that the newline split is already implemented for the text wrapping
> function, there is an opportunity for the user to pass multi-line table
> contents.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)