diff --git a/core/src/main/java/org/elasticsearch/rest/action/support/RestTable.java b/core/src/main/java/org/elasticsearch/rest/action/support/RestTable.java index 549624059fa..3808e58a527 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/support/RestTable.java +++ b/core/src/main/java/org/elasticsearch/rest/action/support/RestTable.java @@ -79,8 +79,9 @@ public class RestTable { if (verbose) { for (int col = 0; col < headers.size(); col++) { DisplayHeader header = headers.get(col); - pad(new Table.Cell(header.display, table.findHeaderByName(header.name)), width[col], request, out); - if (col != lastHeader) { + boolean isLastColumn = col == lastHeader; + pad(new Table.Cell(header.display, table.findHeaderByName(header.name)), width[col], request, out, isLastColumn); + if (!isLastColumn) { out.append(" "); } } @@ -89,8 +90,9 @@ public class RestTable { for (int row = 0; row < table.getRows().size(); row++) { for (int col = 0; col < headers.size(); col++) { DisplayHeader header = headers.get(col); - pad(table.getAsMap().get(header.name).get(row), width[col], request, out); - if (col != lastHeader) { + boolean isLastColumn = col == lastHeader; + pad(table.getAsMap().get(header.name).get(row), width[col], request, out, isLastColumn); + if (!isLastColumn) { out.append(" "); } } @@ -240,6 +242,10 @@ public class RestTable { } public static void pad(Table.Cell cell, int width, RestRequest request, UTF8StreamWriter out) throws IOException { + pad(cell, width, request, out, false); + } + + public static void pad(Table.Cell cell, int width, RestRequest request, UTF8StreamWriter out, boolean isLast) throws IOException { String sValue = renderValue(request, cell.value); int length = sValue == null ? 0 : sValue.length(); byte leftOver = (byte) (width - length); @@ -258,8 +264,11 @@ public class RestTable { if (sValue != null) { out.append(sValue); } - for (byte i = 0; i < leftOver; i++) { - out.append(" "); + // Ignores the leftover spaces if the cell is the last of the column. + if (!isLast) { + for (byte i = 0; i < leftOver; i++) { + out.append(" "); + } } } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.aliases/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.aliases/10_basic.yaml index 73285eaa656..3ee33b0a67b 100755 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.aliases/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.aliases/10_basic.yaml @@ -185,6 +185,6 @@ - match: $body: | /^ - index \s+ alias \s+ \n + index \s+ alias \n test \s+ test_1 \n $/ diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.allocation/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.allocation/10_basic.yaml index c0a5a079e5d..3537da73c81 100755 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.allocation/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.allocation/10_basic.yaml @@ -156,7 +156,7 @@ disk.percent \s+ host \s+ ip \s+ - node \s+ + node \n ( \s* #allow leading spaces to account for right-justified text @@ -199,7 +199,7 @@ $body: | /^ disk.percent \s+ - node \s+ + node \n ( \s+\d* \s+ diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.count/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.count/10_basic.yaml index 30199466616..87ca75a6092 100755 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.count/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.count/10_basic.yaml @@ -19,7 +19,7 @@ - match: $body: | /# epoch timestamp count - ^ \d+ \s \d{2}:\d{2}:\d{2} \s 0 \n $/ + ^ \d+ \s \d{2}:\d{2}:\d{2} \s 0 \n$/ - do: index: @@ -72,5 +72,4 @@ - match: $body: | /^ epoch \s+ timestamp \s+ count \n - \d+ \s+ \d{2}:\d{2}:\d{2} \s+ \d+ \s+ \n $/ - + \d+ \s+ \d{2}:\d{2}:\d{2} \s+ \d+ \n $/ diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.nodes/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.nodes/10_basic.yaml index 77aaecf51c2..2531e6ef025 100755 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.nodes/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.nodes/10_basic.yaml @@ -15,7 +15,7 @@ - match: $body: | - /^ host \s+ ip \s+ heap\.percent \s+ ram\.percent \s+ cpu \s+ load \s+ node\.role \s+ master \s+ name \s+ \n + /^ host \s+ ip \s+ heap\.percent \s+ ram\.percent \s+ cpu \s+ load \s+ node\.role \s+ master \s+ name \n (\S+ \s+ (\d{1,3}\.){3}\d{1,3} \s+ \d+ \s+ \d* \s+ \d* \s+ (-)?\d*(\.\d+)? \s+ [-dc] \s+ [-*mx] \s+ (\S+\s?)+ \n)+ $/ - do: