@@ -730,6 +730,47 @@ class ReaderTest < Minitest::Test
730
730
assert_equal [ 'last line' ] , doc . blocks [ 2 ] . lines
731
731
end
732
732
733
+ test 'should fail to read include file if not UTF-8 encoded and encoding is not specified' do
734
+ input = <<~'EOS'
735
+ ....
736
+ include::fixtures/iso-8859-1.txt[]
737
+ ....
738
+ EOS
739
+
740
+ assert_raises StandardError , 'invalid byte sequence in UTF-8' do
741
+ doc = document_from_string input , safe : :safe , base_dir : DIRNAME
742
+ assert_equal 1 , doc . blocks . size
743
+ refute_equal [ 'Où est l\'hôpital ?' ] , doc . blocks [ 0 ] . lines
744
+ doc . convert
745
+ end
746
+ end
747
+
748
+ test 'should ignore encoding attribute if value is not an valid encoding' do
749
+ input = <<~'EOS'
750
+ ....
751
+ include::fixtures/encoding.adoc[tag=romé,encoding=iso-1000-1]
752
+ ....
753
+ EOS
754
+
755
+ doc = document_from_string input , safe : :safe , base_dir : DIRNAME
756
+ assert_equal 1 , doc . blocks . size
757
+ assert_equal doc . blocks [ 0 ] . lines [ 0 ] . encoding , Encoding ::UTF_8
758
+ assert_equal [ 'Gregory Romé has written an AsciiDoc plugin for the Redmine project management application.' ] , doc . blocks [ 0 ] . lines
759
+ end
760
+
761
+ test 'should use encoding specified by encoding attribute when reading include file' do
762
+ input = <<~'EOS'
763
+ ....
764
+ include::fixtures/iso-8859-1.txt[encoding=iso-8859-1]
765
+ ....
766
+ EOS
767
+
768
+ doc = document_from_string input , safe : :safe , base_dir : DIRNAME
769
+ assert_equal 1 , doc . blocks . size
770
+ assert_equal doc . blocks [ 0 ] . lines [ 0 ] . encoding , Encoding ::UTF_8
771
+ assert_equal [ 'Où est l\'hôpital ?' ] , doc . blocks [ 0 ] . lines
772
+ end
773
+
733
774
test 'unresolved target referenced by include directive is skipped when optional option is set' do
734
775
input = <<~'EOS'
735
776
include::fixtures/{no-such-file}[opts=optional]
0 commit comments