Reject (robot) comments with ranges referring to line 0

Line numbers are 1-based except when they are used to indicate a file
comment. To highlight that behavior, comments are added to the REST
documentation as well as to the code. Those comments additionally
indicate whether the values are inclusive or exclusive.

Change-Id: I4b4409ac25acd2124b3e74cb2ee075206ebae0eb
This commit is contained in:
Alice Kober-Sotzek
2017-03-21 15:19:45 +01:00
parent 73f7323839
commit cd06fb6ddf
4 changed files with 39 additions and 15 deletions

View File

@@ -5386,10 +5386,10 @@ The `CommentRange` entity describes the range of an inline comment.
[options="header",cols="1,^1,5"] [options="header",cols="1,^1,5"]
|=========================== |===========================
|Field Name ||Description |Field Name ||Description
|`start_line` ||The start line number of the range. |`start_line` ||The start line number of the range. (1-based, inclusive)
|`start_character` ||The character position in the start line. |`start_character` ||The character position in the start line. (0-based, inclusive)
|`end_line` ||The end line number of the range. |`end_line` ||The end line number of the range. (1-based, exclusive)
|`end_character` ||The character position in the end line. |`end_character` ||The character position in the end line. (0-based, exclusive)
|=========================== |===========================
[[commit-info]] [[commit-info]]

View File

@@ -29,7 +29,7 @@ public abstract class Comment {
public String path; public String path;
public Side side; public Side side;
public Integer parent; public Integer parent;
public Integer line; public Integer line; // value 0 or null indicates a file comment, normal lines start at 1
public Range range; public Range range;
public String inReplyTo; public String inReplyTo;
public Timestamp updated; public Timestamp updated;
@@ -37,15 +37,15 @@ public abstract class Comment {
public Boolean unresolved; public Boolean unresolved;
public static class Range { public static class Range {
public int startLine; public int startLine; // 1-based, inclusive
public int startCharacter; public int startCharacter; // 0-based, inclusive
public int endLine; public int endLine; // 1-based, exclusive
public int endCharacter; public int endCharacter; // 0-based, exclusive
public boolean isValid() { public boolean isValid() {
return startLine >= 0 return startLine > 0
&& startCharacter >= 0 && startCharacter >= 0
&& endLine >= 0 && endLine > 0
&& endCharacter >= 0 && endCharacter >= 0
&& startLine <= endLine && startLine <= endLine
&& (startLine != endLine || startCharacter <= endCharacter); && (startLine != endLine || startCharacter <= endCharacter);

View File

@@ -62,6 +62,30 @@ public class RangeTest {
assertThat(range).isInvalid(); assertThat(range).isInvalid();
} }
@Test
public void zeroStartLineResultsInInvalidRange() {
Comment.Range range = createRange(0, 2, 19, 10);
assertThat(range).isInvalid();
}
@Test
public void zeroEndLineResultsInInvalidRange() {
Comment.Range range = createRange(13, 2, 0, 10);
assertThat(range).isInvalid();
}
@Test
public void zeroStartCharacterResultsInValidRange() {
Comment.Range range = createRange(13, 0, 19, 10);
assertThat(range).isValid();
}
@Test
public void zeroEndCharacterResultsInValidRange() {
Comment.Range range = createRange(13, 31, 19, 0);
assertThat(range).isValid();
}
@Test @Test
public void startLineGreaterThanEndLineResultsInInvalidRange() { public void startLineGreaterThanEndLineResultsInInvalidRange() {
Comment.Range range = createRange(20, 2, 19, 10); Comment.Range range = createRange(20, 2, 19, 10);

View File

@@ -131,10 +131,10 @@ public class Comment {
} }
public static class Range { public static class Range {
public int startLine; public int startLine; // 1-based, inclusive
public int startChar; public int startChar; // 0-based, inclusive
public int endLine; public int endLine; // 1-based, exclusive
public int endChar; public int endChar; // 0-based, exclusive
public Range(Range r) { public Range(Range r) {
this(r.startLine, r.startChar, r.endLine, r.endChar); this(r.startLine, r.startChar, r.endLine, r.endChar);