From: Fletcher T. Penney Date: Mon, 30 Oct 2017 14:33:59 +0000 (-0400) Subject: FIXED: Strip UTF-8 BOM from main files, not just transcluded files X-Git-Tag: 6.2.3^2~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ad274f8a8e7541a30f76e834c1a8784a09a41763;p=multimarkdown FIXED: Strip UTF-8 BOM from main files, not just transcluded files --- diff --git a/Sources/libMultiMarkdown/transclude.c b/Sources/libMultiMarkdown/transclude.c index 8f4942f..c828e47 100644 --- a/Sources/libMultiMarkdown/transclude.c +++ b/Sources/libMultiMarkdown/transclude.c @@ -285,6 +285,13 @@ DString * scan_file(const char * fname) { while ((bytes = fread(chunk, 1, kBUFFERSIZE, file)) > 0) { d_string_append_c_array(buffer, chunk, bytes); + + if (buffer->currentStringLength < kBUFFERSIZE) { + // Strip BOM + if (strncmp(buffer->str, "\xef\xbb\xbf", 3) == 0) { + d_string_erase(buffer, 0, 3); + } + } } fclose(file); @@ -467,11 +474,6 @@ void mmd_transclude_source(DString * source, const char * search_path, const cha if (mmd_engine_has_metadata(e, &offset)) { d_string_erase(buffer, 0, offset); - } else { - // Do we need to strip BOM? - if (strncmp(buffer->str, "\xef\xbb\xbf", 3) == 0) { - d_string_erase(buffer, 0, 3); - } } mmd_engine_free(e, false); diff --git a/tests/MMD6Tests/BOM.fodt b/tests/MMD6Tests/BOM.fodt new file mode 100644 index 0000000..bb6f76a --- /dev/null +++ b/tests/MMD6Tests/BOM.fodt @@ -0,0 +1,284 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Bibliography + + + + BOM + + + +This file leads with a Byte Order Marker (BOM). + + + diff --git a/tests/MMD6Tests/BOM.html b/tests/MMD6Tests/BOM.html new file mode 100644 index 0000000..cf82022 --- /dev/null +++ b/tests/MMD6Tests/BOM.html @@ -0,0 +1,13 @@ + + + + + BOM + + + +

This file leads with a Byte Order Marker (BOM).

+ + + + diff --git a/tests/MMD6Tests/BOM.htmlc b/tests/MMD6Tests/BOM.htmlc new file mode 100644 index 0000000..109eea3 --- /dev/null +++ b/tests/MMD6Tests/BOM.htmlc @@ -0,0 +1,4 @@ +

Title: BOM +latex config: article

+ +

This file leads with a Byte Order Marker (BOM).

diff --git a/tests/MMD6Tests/BOM.tex b/tests/MMD6Tests/BOM.tex new file mode 100644 index 0000000..d67d849 --- /dev/null +++ b/tests/MMD6Tests/BOM.tex @@ -0,0 +1,8 @@ +\input{mmd6-article-leader} +\def\mytitle{BOM} +\input{mmd6-article-begin} + +This file leads with a Byte Order Marker (BOM). + +\input{mmd6-article-footer} +\end{document} diff --git a/tests/MMD6Tests/BOM.text b/tests/MMD6Tests/BOM.text new file mode 100644 index 0000000..0c44adb --- /dev/null +++ b/tests/MMD6Tests/BOM.text @@ -0,0 +1,4 @@ +Title: BOM +latex config: article + +This file leads with a Byte Order Marker (BOM).