fix line counting with mixed CR and LF

A CR by itself could be incorrectly treated as preceding a later LF,
which would form a CRLF combination if they had been adjacent.

Closes #3033
This commit is contained in:
Matthew Flatt 2020-02-03 15:59:07 -07:00
parent 654f821919
commit 4ed253d66e
2 changed files with 16 additions and 0 deletions

View File

@ -683,6 +683,21 @@
(test 0 syntax-column stx)
(test 1026 syntax-position stx))))
;; Test provided by @wcs4217
(let ([p (open-input-bytes #"\rx\ny")])
(port-count-lines! p)
(test-values '(1 0 1) (lambda () (port-next-location p)))
(test #\return read-char p)
(test-values '(2 0 2) (lambda () (port-next-location p)))
(test #\x read-char p)
(test-values '(2 1 3) (lambda () (port-next-location p)))
(test #\newline read-char p)
(test-values '(3 0 4) (lambda () (port-next-location p)))
(test #\y read-char p)
(test-values '(3 1 5) (lambda () (port-next-location p)))
(test eof read-char p)
(test-values '(3 1 5) (lambda () (port-next-location p))))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Check that if the initial commit thread is killed, then
;; another commit thread is broken, that the second doesn't

View File

@ -1043,6 +1043,7 @@ XFORM_NONGCING static void do_count_lines(Scheme_Port *ip, const char *buffer, i
ip->column = 0;
} else {
ip->charsSinceNewline += c;
ip->was_cr = 0;
}
/* Do the last line to get the column count right and to