Skip to content

Commit 85911c9

Browse files
committed
Properly handle byte-order mark column offsets at the beginnings of files.
1 parent c67e06a commit 85911c9

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6161
- Force using braces if the block is within a `Binary` within the predicate of a loop or conditional.
6262
- Make sure `StringLiteral` and `StringEmbExpr` know that they can be extended by heredocs.
6363
- Ensure `Int` nodes with preceding unary `+` get formatted properly.
64+
- Properly handle byte-order mark column offsets at the beginnings of files.
6465

6566
### Removed
6667

lib/syntax_tree.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ def initialize(start, line)
4848
end
4949
end
5050

51+
# Technically it's possible for the column index to be a negative value if
52+
# there's a BOM at the beginning of the file, which is the reason we need to
53+
# compare it to 0 here.
5154
def [](byteindex)
52-
@indices[byteindex]
55+
@indices[byteindex < 0 ? 0 : byteindex]
5356
end
5457
end
5558

0 commit comments

Comments
 (0)