texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: * tp/ext/epub3.pm (epub_finish): use transliterat


From: Patrice Dumas
Subject: branch master updated: * tp/ext/epub3.pm (epub_finish): use transliterate_protect_file_name on opf file name to replace spaces, and avoid non ascii characters.
Date: Fri, 06 Sep 2024 19:01:05 -0400

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

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 0d43e61e67 * tp/ext/epub3.pm (epub_finish): use 
transliterate_protect_file_name on opf file name to replace spaces, and avoid 
non ascii characters.
0d43e61e67 is described below

commit 0d43e61e67f5170553f8583938d68138c6c74baa
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Sep 7 01:00:59 2024 +0200

    * tp/ext/epub3.pm (epub_finish): use transliterate_protect_file_name
    on opf file name to replace spaces, and avoid non ascii characters.
    
    * tp/t/test_utils.pl (test): add $srcdir.'ext/' to init files search
    path.
    
    * tp/Makefile.tres, tp/t/html_tests.t
    (setfilename_on_top_and_after_node_epub): add test of EPUB generation,
    tesing EPUB generation with files with spaces in their names.
---
 ChangeLog                                          |  12 ++
 tp/Makefile.tres                                   |   2 +
 tp/ext/epub3.pm                                    |   8 +-
 tp/t/html_tests.t                                  |  13 +-
 .../setfilename_on_top_and_after_node_epub.pl      | 239 +++++++++++++++++++++
 .../EPUB/very-badly-placed-setfilename.opf         |  10 +-
 .../EPUB/xhtml/nav_toc.xhtml                       |  16 ++
 .../EPUB/xhtml/very badly placed setfilename.xhtml |  25 +++
 .../META-INF/container.xml                         |   2 +-
 .../mimetype                                       |   1 +
 tp/t/test_utils.pl                                 |   3 +-
 .../EPUB/ose_utf8.opf"                             |   0
 .../META-INF/container.xml"                        |   2 +-
 13 files changed, 321 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 09cb38513c..2827bb31e7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2024-09-06  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/ext/epub3.pm (epub_finish): use transliterate_protect_file_name
+       on opf file name to replace spaces, and avoid non ascii characters.
+
+       * tp/t/test_utils.pl (test): add $srcdir.'ext/' to init files search
+       path.
+
+       * tp/Makefile.tres, tp/t/html_tests.t
+       (setfilename_on_top_and_after_node_epub): add test of EPUB generation,
+       tesing EPUB generation with files with spaces in their names.
+
 2024-09-06  Patrice Dumas  <pertusus@free.fr>
 
        Percent encode file name in internal href
diff --git a/tp/Makefile.tres b/tp/Makefile.tres
index d43aeaed0c..510283ab6a 100644
--- a/tp/Makefile.tres
+++ b/tp/Makefile.tres
@@ -737,6 +737,8 @@ test_files_generated_list = 
$(test_tap_files_generated_list) \
   t/results/html_tests/sectioning_check_menu_structure/res_html \
   t/results/html_tests/set_unit_file_name_filepath.pl \
   t/results/html_tests/set_unit_file_name_filepath/res_html \
+  t/results/html_tests/setfilename_on_top_and_after_node_epub.pl \
+  t/results/html_tests/setfilename_on_top_and_after_node_epub/res_html \
   t/results/html_tests/shortcontents_no_top.pl \
   t/results/html_tests/shorttitlepage.pl \
   t/results/html_tests/simple_only_special_spaces_node.pl \
diff --git a/tp/ext/epub3.pm b/tp/ext/epub3.pm
index 89f7e37028..7ad4b66d49 100644
--- a/tp/ext/epub3.pm
+++ b/tp/ext/epub3.pm
@@ -98,6 +98,7 @@ use Encode qw(decode);
 
 # also for __(
 use Texinfo::Common;
+use Texinfo::Convert::NodeNameNormalization;
 use Texinfo::Convert::Utils;
 use Texinfo::Convert::Text;
 
@@ -628,7 +629,12 @@ sub epub_finish($$)
     return 1;
   }
   my $document_name = $self->get_info('document_name');
-  my $opf_filename = $document_name . '.opf';
+  # We do not only percent encode the file name, as in that case the
+  # checker tells that the file cannot be found, however we can set the
+  # opf file name to anything as long as we are consistent.
+  my $opf_filename
+   = Texinfo::Convert::NodeNameNormalization::transliterate_protect_file_name(
+         $document_name) . '.opf';
   print $container_fh <<EOT;
 <?xml version="1.0"?>
 <container version="1.0" 
xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
diff --git a/tp/t/html_tests.t b/tp/t/html_tests.t
index 6b5068470e..78b7e98df8 100644
--- a/tp/t/html_tests.t
+++ b/tp/t/html_tests.t
@@ -1520,6 +1520,16 @@ undef, {'test_file' => 
'simple_only_special_spaces_node.texi',
         'init_files' => ['no_navigation.pm']},
        # needed to test for the bug
        {'SPLIT' => 'node'}],
+# also in *sectioning.t.  Here we are interested by testing spaces
+# in filenames.
+['setfilename_on_top_and_after_node_epub',
+'@node Top
+@top In top @setfilename very badly placed setfilename
+
+@setfilename a bit too late
+', {'init_files' => ['epub3.pm'],
+    'test_input_file_name' => 'very badly placed setfilename.texi'},
+   {'EPUB_CREATE_CONTAINER_FILE' => 0}],
 );
 
 
@@ -1531,7 +1541,8 @@ foreach my $test (@test_cases_text) {
 }
 foreach my $test (@file_tests) {
   push @{$test->[2]->{'test_formats'}}, 'file_html';
-  $test->[2]->{'test_input_file_name'} = $test->[0] . '.texi';
+  $test->[2]->{'test_input_file_name'} = $test->[0] . '.texi'
+    unless (exists($test->[2]->{'test_input_file_name'}));
   $test->[2]->{'full_document'} = 1 unless 
(exists($test->[2]->{'full_document'}));
 }
 foreach my $test (@test_cases_file_text) {
diff --git a/tp/t/results/html_tests/setfilename_on_top_and_after_node_epub.pl 
b/tp/t/results/html_tests/setfilename_on_top_and_after_node_epub.pl
new file mode 100644
index 0000000000..f68e0f1766
--- /dev/null
+++ b/tp/t/results/html_tests/setfilename_on_top_and_after_node_epub.pl
@@ -0,0 +1,239 @@
+use vars qw(%result_texis %result_texts %result_trees %result_errors 
+   %result_indices %result_sectioning %result_nodes %result_menus
+   %result_floats %result_converted %result_converted_errors 
+   %result_elements %result_directions_text %result_indices_sort_strings);
+
+use utf8;
+
+$result_trees{'setfilename_on_top_and_after_node_epub'} = {
+  'contents' => [
+    {
+      'contents' => [
+        {
+          'type' => 'preamble_before_content'
+        }
+      ],
+      'type' => 'before_node_section'
+    },
+    {
+      'args' => [
+        {
+          'contents' => [
+            {
+              'text' => 'Top'
+            }
+          ],
+          'info' => {
+            'spaces_after_argument' => {
+              'text' => '
+'
+            }
+          },
+          'type' => 'line_arg'
+        }
+      ],
+      'cmdname' => 'node',
+      'extra' => {
+        'is_target' => 1,
+        'normalized' => 'Top'
+      },
+      'info' => {
+        'spaces_before_argument' => {
+          'text' => ' '
+        }
+      },
+      'source_info' => {
+        'line_nr' => 1
+      }
+    },
+    {
+      'args' => [
+        {
+          'contents' => [
+            {
+              'text' => 'In top '
+            },
+            {
+              'args' => [
+                {
+                  'contents' => [
+                    {
+                      'text' => 'very badly placed setfilename'
+                    }
+                  ],
+                  'info' => {
+                    'spaces_after_argument' => {
+                      'text' => '
+'
+                    }
+                  },
+                  'type' => 'line_arg'
+                }
+              ],
+              'cmdname' => 'setfilename',
+              'extra' => {
+                'text_arg' => 'very badly placed setfilename'
+              },
+              'info' => {
+                'spaces_before_argument' => {
+                  'text' => ' '
+                }
+              },
+              'source_info' => {
+                'line_nr' => 2
+              }
+            }
+          ],
+          'type' => 'line_arg'
+        }
+      ],
+      'cmdname' => 'top',
+      'contents' => [
+        {
+          'text' => '
+',
+          'type' => 'empty_line'
+        },
+        {
+          'args' => [
+            {
+              'contents' => [
+                {
+                  'text' => 'a bit too late'
+                }
+              ],
+              'info' => {
+                'spaces_after_argument' => {
+                  'text' => '
+'
+                }
+              },
+              'type' => 'line_arg'
+            }
+          ],
+          'cmdname' => 'setfilename',
+          'extra' => {
+            'text_arg' => 'a bit too late'
+          },
+          'info' => {
+            'spaces_before_argument' => {
+              'text' => ' '
+            }
+          },
+          'source_info' => {
+            'line_nr' => 4
+          }
+        }
+      ],
+      'extra' => {},
+      'info' => {
+        'spaces_before_argument' => {
+          'text' => ' '
+        }
+      },
+      'source_info' => {
+        'line_nr' => 2
+      }
+    }
+  ],
+  'type' => 'document_root'
+};
+
+$result_texis{'setfilename_on_top_and_after_node_epub'} = '@node Top
+@top In top @setfilename very badly placed setfilename
+
+@setfilename a bit too late
+';
+
+
+$result_texts{'setfilename_on_top_and_after_node_epub'} = 'In top 
+*******
+
+';
+
+$result_sectioning{'setfilename_on_top_and_after_node_epub'} = {
+  'extra' => {
+    'section_childs' => [
+      {
+        'cmdname' => 'top',
+        'extra' => {
+          'associated_node' => {
+            'cmdname' => 'node',
+            'extra' => {
+              'normalized' => 'Top'
+            }
+          },
+          'section_level' => 0,
+          'sectioning_root' => {}
+        }
+      }
+    ],
+    'section_level' => -1
+  }
+};
+$result_sectioning{'setfilename_on_top_and_after_node_epub'}{'extra'}{'section_childs'}[0]{'extra'}{'sectioning_root'}
 = $result_sectioning{'setfilename_on_top_and_after_node_epub'};
+
+$result_nodes{'setfilename_on_top_and_after_node_epub'} = [
+  {
+    'cmdname' => 'node',
+    'extra' => {
+      'associated_section' => {
+        'cmdname' => 'top',
+        'extra' => {}
+      },
+      'normalized' => 'Top'
+    }
+  }
+];
+
+$result_menus{'setfilename_on_top_and_after_node_epub'} = [
+  {
+    'extra' => {
+      'normalized' => 'Top'
+    }
+  }
+];
+
+$result_errors{'setfilename_on_top_and_after_node_epub'} = [
+  {
+    'error_line' => 'warning: @setfilename should only appear at the beginning 
of a line
+',
+    'line_nr' => 2,
+    'text' => '@setfilename should only appear at the beginning of a line',
+    'type' => 'warning'
+  },
+  {
+    'error_line' => 'warning: @setfilename should not appear on @top line
+',
+    'line_nr' => 2,
+    'text' => '@setfilename should not appear on @top line',
+    'type' => 'warning'
+  },
+  {
+    'error_line' => 'warning: @setfilename after the first element
+',
+    'line_nr' => 2,
+    'text' => '@setfilename after the first element',
+    'type' => 'warning'
+  },
+  {
+    'error_line' => 'warning: multiple @setfilename
+',
+    'line_nr' => 4,
+    'text' => 'multiple @setfilename',
+    'type' => 'warning'
+  },
+  {
+    'error_line' => 'warning: @setfilename after the first element
+',
+    'line_nr' => 4,
+    'text' => '@setfilename after the first element',
+    'type' => 'warning'
+  }
+];
+
+
+$result_floats{'setfilename_on_top_and_after_node_epub'} = {};
+
+
+1;
diff --git 
"a/tp/tests/encoded/res_parser/non_ascii_test_epub/os\303\251_utf8_epub_package/EPUB/os\303\251_utf8.opf"
 b/tp/t/results/html_tests/setfilename_on_top_and_after_node_epub/res_html/very 
badly placed setfilename_epub_package/EPUB/very-badly-placed-setfilename.opf
similarity index 55%
copy from 
"tp/tests/encoded/res_parser/non_ascii_test_epub/os\303\251_utf8_epub_package/EPUB/os\303\251_utf8.opf"
copy to 
tp/t/results/html_tests/setfilename_on_top_and_after_node_epub/res_html/very 
badly placed setfilename_epub_package/EPUB/very-badly-placed-setfilename.opf
index d2c3042703..77c631af20 100644
--- 
"a/tp/tests/encoded/res_parser/non_ascii_test_epub/os\303\251_utf8_epub_package/EPUB/os\303\251_utf8.opf"
+++ 
b/tp/t/results/html_tests/setfilename_on_top_and_after_node_epub/res_html/very 
badly placed setfilename_epub_package/EPUB/very-badly-placed-setfilename.opf 
@@ -1,19 +1,15 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <package xmlns="http://www.idpf.org/2007/opf"; version="3.0" 
unique-identifier="texi-uid">
    <metadata xmlns:dc="http://purl.org/dc/elements/1.1/";>
-      <dc:identifier id="texi-uid">texinfo:osé_utf8</dc:identifier>
-      <dc:title>Tôp</dc:title>
+      <dc:identifier id="texi-uid">texinfo:very badly placed 
setfilename</dc:identifier>
+      <dc:title>In top </dc:title>
       <dc:language>en</dc:language>
    </metadata>
    <manifest>
       <item id="nav" properties="nav" media-type="application/xhtml+xml" 
href="xhtml/nav_toc.xhtml"/>
-      <item id="unit1" media-type="application/xhtml+xml" 
href="xhtml/osé_utf8.xhtml"/>
-      <item id="unit2" media-type="application/xhtml+xml" 
href="xhtml/Chapteur.xhtml"/>
-      <item id="image1" media-type="image/png" href="images/1-an_image.png"/>
-      <item id="image2" media-type="image/png" href="images/2-an_image.png"/>
+      <item id="unit1" media-type="application/xhtml+xml" href="xhtml/very 
badly placed setfilename.xhtml"/>
    </manifest>
    <spine>
       <itemref idref="unit1"/>
-      <itemref idref="unit2"/>
    </spine>
 </package>
diff --git 
a/tp/t/results/html_tests/setfilename_on_top_and_after_node_epub/res_html/very 
badly placed setfilename_epub_package/EPUB/xhtml/nav_toc.xhtml 
b/tp/t/results/html_tests/setfilename_on_top_and_after_node_epub/res_html/very 
badly placed setfilename_epub_package/EPUB/xhtml/nav_toc.xhtml
new file mode 100644
index 0000000000..6d4df7fa0a
--- /dev/null
+++ 
b/tp/t/results/html_tests/setfilename_on_top_and_after_node_epub/res_html/very 
badly placed setfilename_epub_package/EPUB/xhtml/nav_toc.xhtml       
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<html xmlns="http://www.w3.org/1999/xhtml"; 
xmlns:epub="http://www.idpf.org/2007/ops";>
+<head>
+<meta charset="utf-8" />
+<title>In top  - Table of contents</title>
+</head>
+<body>
+<nav epub:type="toc" id="nav">
+<h1>Table of contents</h1>
+
+<ol>
+ <li><a href="very%20badly%20placed%20setfilename.xhtml">In top </a></li>
+</ol>
+</nav>
+</body>
+</html>
diff --git 
a/tp/t/results/html_tests/setfilename_on_top_and_after_node_epub/res_html/very 
badly placed setfilename_epub_package/EPUB/xhtml/very badly placed 
setfilename.xhtml 
b/tp/t/results/html_tests/setfilename_on_top_and_after_node_epub/res_html/very 
badly placed setfilename_epub_package/EPUB/xhtml/very badly placed 
setfilename.xhtml
new file mode 100644
index 0000000000..62e0f7f2c0
--- /dev/null
+++ 
b/tp/t/results/html_tests/setfilename_on_top_and_after_node_epub/res_html/very 
badly placed setfilename_epub_package/EPUB/xhtml/very badly placed 
setfilename.xhtml 
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml";>
+<!-- Created by texinfo, http://www.gnu.org/software/texinfo/ -->
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+<title>In top </title>
+
+<meta name="description" content="In top "/>
+<meta name="keywords" content="In top "/>
+<meta name="resource-type" content="document"/>
+<meta name="distribution" content="global"/>
+<meta name="viewport" content="width=device-width,initial-scale=1"/>
+
+<link href="#Top" rel="start" title="In top "/>
+
+
+</head>
+
+<body lang="en">
+<a class="node" id="Top"></a><a class="top" id="In-top-"></a>
+
+
+</body>
+</html>
diff --git 
"a/tp/tests/encoded/res_parser/non_ascii_test_epub/os\303\251_utf8_epub_package/META-INF/container.xml"
 b/tp/t/results/html_tests/setfilename_on_top_and_after_node_epub/res_html/very 
badly placed setfilename_epub_package/META-INF/container.xml
similarity index 75%
copy from 
"tp/tests/encoded/res_parser/non_ascii_test_epub/os\303\251_utf8_epub_package/META-INF/container.xml"
copy to 
tp/t/results/html_tests/setfilename_on_top_and_after_node_epub/res_html/very 
badly placed setfilename_epub_package/META-INF/container.xml
index 6640a792e1..c46272314f 100644
--- 
"a/tp/tests/encoded/res_parser/non_ascii_test_epub/os\303\251_utf8_epub_package/META-INF/container.xml"
+++ 
b/tp/t/results/html_tests/setfilename_on_top_and_after_node_epub/res_html/very 
badly placed setfilename_epub_package/META-INF/container.xml 
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <container version="1.0" 
xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
     <rootfiles>
-        <rootfile full-path="EPUB/osé_utf8.opf"
+        <rootfile full-path="EPUB/very-badly-placed-setfilename.opf"
             media-type="application/oebps-package+xml" />      
     </rootfiles>
 </container>
diff --git 
a/tp/t/results/html_tests/setfilename_on_top_and_after_node_epub/res_html/very 
badly placed setfilename_epub_package/mimetype 
b/tp/t/results/html_tests/setfilename_on_top_and_after_node_epub/res_html/very 
badly placed setfilename_epub_package/mimetype
new file mode 100644
index 0000000000..57ef03f24a
--- /dev/null
+++ 
b/tp/t/results/html_tests/setfilename_on_top_and_after_node_epub/res_html/very 
badly placed setfilename_epub_package/mimetype       
@@ -0,0 +1 @@
+application/epub+zip
\ No newline at end of file
diff --git a/tp/t/test_utils.pl b/tp/t/test_utils.pl
index 39a67351f1..681f8b42f8 100644
--- a/tp/t/test_utils.pl
+++ b/tp/t/test_utils.pl
@@ -881,7 +881,8 @@ sub test($$)
   my $init_files_options
       = Texinfo::Config::GNUT_initialize_customization('',
                                    $test_customization_defaults, {});
-  my $init_file_directories = [$srcdir.'init/', $srcdir.'t/init/'];
+  my $init_file_directories = [$srcdir.'init/', $srcdir.'t/init/',
+                               $srcdir.'ext/'];
   # the init file names should be binary strings.  Since they
   # are not encoded here, ascii file names should be used or they
   # should be encoded in test specification files.
diff --git 
"a/tp/tests/encoded/res_parser/non_ascii_test_epub/os\303\251_utf8_epub_package/EPUB/os\303\251_utf8.opf"
 
"b/tp/tests/encoded/res_parser/non_ascii_test_epub/os\303\251_utf8_epub_package/EPUB/ose_utf8.opf"
similarity index 100%
rename from 
"tp/tests/encoded/res_parser/non_ascii_test_epub/os\303\251_utf8_epub_package/EPUB/os\303\251_utf8.opf"
rename to 
"tp/tests/encoded/res_parser/non_ascii_test_epub/os\303\251_utf8_epub_package/EPUB/ose_utf8.opf"
diff --git 
"a/tp/tests/encoded/res_parser/non_ascii_test_epub/os\303\251_utf8_epub_package/META-INF/container.xml"
 
"b/tp/tests/encoded/res_parser/non_ascii_test_epub/os\303\251_utf8_epub_package/META-INF/container.xml"
index 6640a792e1..3fead36985 100644
--- 
"a/tp/tests/encoded/res_parser/non_ascii_test_epub/os\303\251_utf8_epub_package/META-INF/container.xml"
+++ 
"b/tp/tests/encoded/res_parser/non_ascii_test_epub/os\303\251_utf8_epub_package/META-INF/container.xml"
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <container version="1.0" 
xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
     <rootfiles>
-        <rootfile full-path="EPUB/osé_utf8.opf"
+        <rootfile full-path="EPUB/ose_utf8.opf"
             media-type="application/oebps-package+xml" />      
     </rootfiles>
 </container>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]