Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 202b0ef

Browse files
committed
Fix a message bug.
If a point span appeared past the end of a file, and that file *didn't* end with a trailing newline, that span would be printed as though it pointed at the last character of the file. [email protected] Review URL: https://codereview.chromium.org//2056913002 .
1 parent 536e59d commit 202b0ef

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 1.2.3
2+
3+
* Fix a bug where a point span at the end of a file without a trailing newline
4+
would be printed incorrectly.
5+
16
# 1.2.2
27

38
* Allow `SourceSpanException.message`, `SourceSpanFormatException.source`, and

lib/src/span_mixin.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ abstract class SourceSpanMixin implements SourceSpan {
7070
}
7171
var endIndex = context.indexOf('\n');
7272
textLine = endIndex == -1 ? context : context.substring(0, endIndex + 1);
73-
column = math.min(column, textLine.length - 1);
73+
column = math.min(column, textLine.length);
7474
} else {
7575
textLine = text.split("\n").first;
7676
column = 0;

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: source_span
2-
version: 1.2.2
2+
version: 1.2.3
33
author: Dart Team <[email protected]>
44
description: A library for identifying source spans and locations.
55
homepage: https://github.com/dart-lang/source_span

test/file_message_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ zip zap zop
5959
^"""));
6060
});
6161

62+
test("works for a point span at the end of the file with no trailing newline",
63+
() {
64+
file = new SourceFile("zip zap zop");
65+
expect(file.location(11).pointSpan().message("oh no"), equals("""
66+
line 1, column 12: oh no
67+
zip zap zop
68+
^"""));
69+
});
70+
6271
test("works for a point span in an empty file", () {
6372
expect(new SourceFile("").location(0).pointSpan().message("oh no"),
6473
equals("""

0 commit comments

Comments
 (0)