[latex3-commits] [l3svn] branch master updated: Read files in binary mode when creating MD5 sum (LuaTeX)

noreply at latex-project.org noreply at latex-project.org
Tue Sep 19 09:41:50 CEST 2017


This is an automated email from the git hooks/post-receive script.

joseph pushed a commit to branch master
in repository l3svn.

The following commit(s) were added to refs/heads/master by this push:
       new  00750c2   Read files in binary mode when creating MD5 sum (LuaTeX)
00750c2 is described below

commit 00750c277887df078a797ebf13d2886745f7c06f
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Tue Sep 19 08:20:40 2017 +0100

    Read files in binary mode when creating MD5 sum (LuaTeX)
    
    This means we get the same result for all engines on the same platform.
    
    This reverts commit 57f1806c7ced2677ca0a3c03483d1b95fe155b2f.
---
 l3kernel/l3candidates.dtx        |    6 +++++-
 l3kernel/l3luatex.dtx            |   11 +++++++----
 l3kernel/testfiles/m3file001.lvt |   20 ++++++--------------
 3 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/l3kernel/l3candidates.dtx b/l3kernel/l3candidates.dtx
index 69e62bd..e8367a4 100644
--- a/l3kernel/l3candidates.dtx
+++ b/l3kernel/l3candidates.dtx
@@ -236,7 +236,11 @@
 %   Searches for \meta{file name} using the current \TeX{} search
 %   path and the additional paths controlled by \cs{file_path_include:n}.
 %   If found, sets the \meta{str var} to the MD5 sum generated from the
-%   content of the file.
+%   content of the file. The file is read as bytes, which means that in
+%   contrast to most \TeX{} behaviour there will be a difference in result
+%   depending on the line endings used in text files. The same file will
+%   produce the same result between different engines: the algorithm used
+%   is the same in all cases.
 %   Where the file is not found, the \meta{str var} will be empty.
 % \end{function}
 %
diff --git a/l3kernel/l3luatex.dtx b/l3kernel/l3luatex.dtx
index 9841a47..f52a95f 100644
--- a/l3kernel/l3luatex.dtx
+++ b/l3kernel/l3luatex.dtx
@@ -140,8 +140,10 @@
 %   \begin{syntax}
 %     \cs{l3kernel.filemdfivesum}|(|\meta{file}|)|
 %   \end{syntax}
-%   Returns the of the MD5 sum of the file contents read as bytes. If the
-%   \meta{file} is not found, nothing is returned with \emph{no error raised}.
+%   Returns the of the MD5 sum of the file contents read as bytes; note that
+%   the result will depend on the nature of the line endings used in the file,
+%   in contrast to normal \TeX{} behaviour. If the \meta{file} is not found,
+%   nothing is returned with \emph{no error raised}.
 % \end{function}
 %
 % \begin{function}{l3kernel.filemoddate}
@@ -321,12 +323,13 @@ l3kernel.charcat = charcat
 %   Read an entire file and hash it: the hash function itself is a built-in.
 %   As Lua is byte-based there is no work needed here in terms of UTF-8
 %   (see \pkg{pdftexcmds} and how it handles strings that have passed through
-%   \LuaTeX{}).
+%   \LuaTeX{}). The file is read in binary mode so that no line ending
+%   normalisation occurs.
 %    \begin{macrocode}
 local function filemdfivesum(name)
   local file =  kpse_find(name, "tex", true)
   if file then
-    local f = open(file, "r")
+    local f = open(file, "rb")
     if f then
       local data = f:read("*a")
       escapehex(md5_sum(data))
diff --git a/l3kernel/testfiles/m3file001.lvt b/l3kernel/testfiles/m3file001.lvt
index e65afc1..bf33a51 100644
--- a/l3kernel/testfiles/m3file001.lvt
+++ b/l3kernel/testfiles/m3file001.lvt
@@ -143,28 +143,20 @@
     \file_get_size:nN { filetest.txt } \l_tmpb_str
     \sys_if_engine_xetex:F
       {
-        \sys_if_engine_luatex:TF
+        \int_compare:nNnTF \l_tmpb_str = { 120 }
           {
-            % LuaTeX always gives the same sum
+            % Unix line endings
             \str_if_eq:VnTF \l_tmpa_str { 4F918CB10404DD50E3C1B9990FF54D4A }
               \TRUE \ERROR
           }
           {
-            % Unix line endings
-            \int_compare:nNnTF \l_tmpb_str = { 120 }
+            \int_compare:nNnTF \l_tmpb_str = { 123 }
               {
-                \str_if_eq:VnTF \l_tmpa_str { 4F918CB10404DD50E3C1B9990FF54D4A }
+                 % Windows line endings
+                \str_if_eq:VnTF \l_tmpa_str { FA408C34EC7616533C50F8643B7949B6 }
                   \TRUE \ERROR
               }
-              {
-                % Windows line endings
-                \int_compare:nNnTF \l_tmpb_str = { 123 }
-                  {
-                    \str_if_eq:VnTF \l_tmpa_str { FA408C34EC7616533C50F8643B7949B6 }
-                      \TRUE \ERROR
-                  }
-                  { \ERROR }
-              }
+              \ERROR
           }
       }
     \file_get_mdfive_hash:nN { NotAFile.txt } \l_tmpa_str

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the latex3-commits mailing list