-
Notifications
You must be signed in to change notification settings - Fork 17
Don't allow CR to act as newline when it is followed by LF #81
Conversation
This fixes an error I encountered (https://github.com/dart-lang/string_scanner/issues/80) when scanning a zero-length match when between a CR and LF. It removes some special handling of \r's that seemed to complicate things. Now, \r is just ignored and only \n is treated as the end of a line. Note: This partially reverts some changes made in 27d20a3 that seemed to be the cause of the error - however the changes added in that change still pass with my changes, and I added some additional tests. Fixes https://github.com/dart-lang/string_scanner/issues/80
@nex3 interested in your thoughts on this since you seem to have committed here recently and made the commit noted above that this changes. |
Looking at 27d20a3 again, I think the intention may have been to also handle a So it's possible this change is not completely consistent (and more tests are needed). However, I'm unsure about this behaviour - should a bare (note: PowerShell uses backticks for escape characters)
We should agree what the behaviour should be here and add additional tests. |
I think practically only I'm less familiar w/ this package specifically but am comforted by existing + new tests passing. If there are more tests you feel we should have, please add them :) |
@@ -61,14 +58,14 @@ class LineScanner extends StringScanner { | |||
} | |||
} else { | |||
final newlines = _newlinesIn(string.substring(newPosition, oldPosition)); | |||
if (_betweenCRLF) newlines.removeLast(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line has likely been a bug since this landed. It was introduced during code review.
I'm less comforted to find that we might be missing tests covering that behavior, since the behavior changed during code review and no one noticed. I will run this against a larger set of tests and see if anything crops up. Edit: Although I don't know if it adds much confidence, since I won't be running any windows tests. |
The intention was that |
I have pushed changes to handle The changes were a little complex when moving the I've added many more tests and everything is passing, but please review carefully and let me know if you think there are additional cases we need tests for. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. Thanks for following through with the solution that handles solo /r
I think I found a bug here, going to add some new tests and fix if necessary. |
Pushed some additional tests + fixes for:
|
Fixes https://github.com/dart-lang/string_scanner/issues/80 This fixes an error when scanning a zero-length match when between a CR and LF. * Fix typo * comment nits * Fix some bugs when setting position if the current position is between \r\n --------- Co-authored-by: Nate Bosch <[email protected]>
This fixes an error I encountered (dart-lang/tools#1797) when scanning a zero-length match when between a CR and LF. It removes some special handling of \r's that seemed to complicate things. Now, \r is just ignored and only \n is treated as the end of a line.
Note: This partially reverts some changes made in 27d20a3 that seemed to be the cause of the error - however the changes added in that change still pass with my changes, and I added some additional tests.
Fixes dart-lang/tools#1797