Skip to content

Use ':raw' for reading binary files in t/content_type.t#65

Open
MatthiasMuth wants to merge 1 commit into
rjbs:mainfrom
MatthiasMuth:correct-test-binary-no-utf8
Open

Use ':raw' for reading binary files in t/content_type.t#65
MatthiasMuth wants to merge 1 commit into
rjbs:mainfrom
MatthiasMuth:correct-test-binary-no-utf8

Conversation

@MatthiasMuth

Copy link
Copy Markdown

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, depending on the user's environment.

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 (note that the _slurp function 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant