The sort command does not work when trying to sort on the last field
--------------------------------------------------------------------

                 Key: KARAF-134
                 URL: https://issues.apache.org/jira/browse/KARAF-134
             Project: Karaf
          Issue Type: Bug
    Affects Versions: 2.0.0
            Reporter: Guillaume Nodet


The command 
{code}
packages:exports  | sort -t "\)" -k 2
{code}
does not work.

The patch is easy, but i'd like a unit test before committing it.

{code}
diff --git 
a/shell/commands/src/main/java/org/apache/karaf/shell/commands/SortAction.java 
b/shell/commands/src/main/java/org/apache/karaf/shell/commands/SortAction.java
index 758df96..27452cd 100644
--- 
a/shell/commands/src/main/java/org/apache/karaf/shell/commands/SortAction.java
+++ 
b/shell/commands/src/main/java/org/apache/karaf/shell/commands/SortAction.java
@@ -233,7 +233,7 @@ public class SortAction extends OsgiCommandSupport {
         protected int[] getSortKey(String str, List<Integer> fields, Key key) {
             int start;
             int end;
-            if (key.startField * 2 < fields.size()) {
+            if (key.startField * 2 <= fields.size()) {
                 start = fields.get((key.startField - 1) * 2);
                 if (key.ignoreBlanksStart) {
                     while (start < fields.get((key.startField - 1) * 2 + 1) && 
Character.isWhitespace(str.charAt(start))) {
@@ -246,7 +246,7 @@ public class SortAction extends OsgiCommandSupport {
             } else {
                 start = 0;
             }
-            if (key.endField > 0 && key.endField * 2 < fields.size()) {
+            if (key.endField > 0 && key.endField * 2 <= fields.size()) {
                 end =  fields.get((key.endField - 1) * 2);
                 if (key.ignoreBlanksEnd) {
                     while (end < fields.get((key.endField - 1) * 2 + 1) && 
Character.isWhitespace(str.charAt(end))) {
{code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to