Use ':raw' for reading binary files in t/content_type.t#65
Open
MatthiasMuth wants to merge 1 commit into
Open
Conversation
Using ':raw' mode explicitly in the slurp function in t/content_type.t is the correct way to unconditionally read binary files in binary mode. Without ':raw', the installation of the module can fail. It will fail if the user has exported the PERL_UNICODE environment variable as an empty string and the locale environment variables (LC_ALL, LC_CTYPE, and LANG, in the order of decreasing precedence) indicate a UTF-8 locale, (e.g. 'C.UTF-8'). In that case, all standard I/O handles and the default open() layer use UTF-8 conversion for input and output (see the -C option in 'perldoc perlrun' for more details). This causes t/content_type.t to read all (binary) test input files using UTF-8 decoding. At least one warning is produced for a \xD5 character that does not map to a valid Unicode character. The test program then aborts with a 'wide character in subroutine entry' error message. Even if the module itself is correct, it will not be installed in that case, due to the test producing a 'false negative' by aborting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Using
:rawmode explicitly in theslurpfunction int/content_type.tis the correct way to unconditionally read binary files in binary mode.Without
:raw, the installation of the module can fail, depending on the user's environment.It will fail if the user has exported the
PERL_UNICODEenvironment variable as an empty string and the locale environment variables (LC_ALL,LC_CTYPE, andLANG, in the order of decreasing precedence) indicate a UTF-8 locale, (e.g.'C.UTF-8').In that case, all standard I/O handles and the default
open()layer use UTF-8 conversion for input and output (see the-Coption in perldoc perlrun for more details).This causes
t/content_type.tto read all (binary) test input files using UTF-8 decoding. At least one warning is produced for a\xD5character that does not map to a valid Unicode character.The test program then aborts with a
'wide character in subroutine entry'error message.Even if the module itself is correct (note that the
_slurpfunction in the module itself correctly uses:raw), it will not be installed under those special circumstances, due to the test producing a 'false negative' by aborting.