Subject: | IO::Prompter does not remove EOL on Windows |
Date: | Tue, 4 Oct 2016 08:00:45 -0400 |
To: | bug-IO-Prompter [...] rt.cpan.org |
From: | "A. Sinan Unur" <sinan [...] unur.com> |
Hello:
Recently, while answering a question on Stackoverflow[1], I noticed an
oddity on Windows:
C:\> perl -MIO::Prompter -E "$x = prompt 'p: ', -echo => '*'; say qq{>>>$x<<<}"
p: ********
<<<12345678
Note the password is not printed between the angle brackets, but after.
C:\> perl -MIO::Prompter -E "$x = prompt 'p: ', -echo => '*'; say
qq{>>>$x<<<}" | xxd
00000000: 3e3e 3e31 3233 3435 3637 380d 3c3c 3c0d >>>12345678.<<<.
00000010: 0a
Note the solitary `x0d` after `x38`. I am not exactly sure why this
happens, but it may have something to do with an interaction between
reading in 'raw' mode[2] and 'chomp'ing[3] or where input matching
`\R` is appended to the buffer[4].
I think at [4], in raw mode, the module is reading just the CR part of the CRLF.
The least disruptive change might be to replace the chomp with `s/\R\z//`.
HTH,
-- Sinan
[1]: https://stackoverflow.com/a/39801196/100754
[2]: https://metacpan.org/source/DCONWAY/IO-Prompter-0.004014/lib/IO/Prompter.pm#L1202
[3]: https://metacpan.org/source/DCONWAY/IO-Prompter-0.004014/lib/IO/Prompter.pm#L240
[4]: https://metacpan.org/source/DCONWAY/IO-Prompter-0.004014/lib/IO/Prompter.pm#L1413