diff --git a/sax/m_sax_xml_source.F90 b/sax/m_sax_xml_source.F90 index 21c238e6..5b668a80 100644 --- a/sax/m_sax_xml_source.F90 +++ b/sax/m_sax_xml_source.F90 @@ -205,6 +205,11 @@ subroutine parse_declaration(f, eof, es, standalone) ch => null() do c = get_char_from_file(f, XML1_0, eof, es) + ! If we don't have a sensible character it may be a Byte + ! Order Mark. Skip it and carry on to see if we can still + ! read. + if (parse_state == XD_0 .and. c /= '<') & + cycle if (eof) then call rewind_source(f) exit diff --git a/sax/test/test_sax_fsm_1_utf16_bom.in b/sax/test/test_sax_fsm_1_utf16_bom.in new file mode 100644 index 00000000..f2b77061 Binary files /dev/null and b/sax/test/test_sax_fsm_1_utf16_bom.in differ diff --git a/sax/test/test_sax_fsm_1_utf8_bom.in b/sax/test/test_sax_fsm_1_utf8_bom.in new file mode 100644 index 00000000..eabf51ce --- /dev/null +++ b/sax/test/test_sax_fsm_1_utf8_bom.in @@ -0,0 +1,2 @@ + + diff --git a/sax/test/test_sax_parser_6.f90 b/sax/test/test_sax_parser_6.f90 new file mode 100644 index 00000000..f14b8ad4 --- /dev/null +++ b/sax/test/test_sax_parser_6.f90 @@ -0,0 +1,15 @@ +program test_sax_reader + + use FoX_sax + type(xml_t) :: xp + integer :: iostat + + call open_xml_file(xp, "test_sax_fsm_1_utf8_bom.in", iostat) + + write(*,'(i1)') iostat + + call parse(xp) + + call close_xml_t(xp) + +end program test_sax_reader diff --git a/sax/test/test_sax_parser_6.out b/sax/test/test_sax_parser_6.out new file mode 100644 index 00000000..573541ac --- /dev/null +++ b/sax/test/test_sax_parser_6.out @@ -0,0 +1 @@ +0 diff --git a/sax/test/test_sax_parser_7.f90 b/sax/test/test_sax_parser_7.f90 new file mode 100644 index 00000000..9f181a7a --- /dev/null +++ b/sax/test/test_sax_parser_7.f90 @@ -0,0 +1,15 @@ +program test_sax_reader + + use FoX_sax + type(xml_t) :: xp + integer :: iostat + + call open_xml_file(xp, "test_sax_fsm_1_utf16_bom.in", iostat) + + write(*,'(i1)') iostat + + call parse(xp) + + call close_xml_t(xp) + +end program test_sax_reader diff --git a/sax/test/test_sax_parser_7.out b/sax/test/test_sax_parser_7.out new file mode 100644 index 00000000..2ccae3f2 --- /dev/null +++ b/sax/test/test_sax_parser_7.out @@ -0,0 +1,3 @@ +0 +ERROR(FoX) +Illegal character found at test_sax_fsm_1_utf16_bom.in:0:3 Error parsing XML declaration (Possibly near line=0 col=3)