Skip to content

Commit

Permalink
Make countColumn robust to passing in an invalid end pos
Browse files Browse the repository at this point in the history
FIX: `countColumn` no longer loops infinitely when given a `to` that's higher
than the input string's length.

Issue codemirror/dev#1502
  • Loading branch information
marijnh committed Jan 10, 2025
1 parent 04a4ad7 commit 27e1977
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {findClusterBreak} from "./char"
/// taking extending characters and tab size into account.
export function countColumn(string: string, tabSize: number, to = string.length): number {
let n = 0
for (let i = 0; i < to;) {
for (let i = 0; i < to && i < string.length;) {
if (string.charCodeAt(i) == 9) {
n += tabSize - (n % tabSize)
i++
Expand Down

0 comments on commit 27e1977

Please sign in to comment.