Fixed bug in handling null metadata

This commit is contained in:
Kevin Boone
2022-05-19 08:49:17 +01:00
parent 02f69e6243
commit 7aea09acee
4 changed files with 20 additions and 11 deletions

View File

@@ -1,4 +1,4 @@
VERSION := 2.04
VERSION := 2.05
CC := gcc
CFLAGS := -Wall -fPIC -fPIE
LDFLAGS := -pie -s

View File

@@ -1,6 +1,6 @@
# epub2txt -- Extract text from EPUB documents
Version 2.04, April 2022
Version 2.05, May 2022
## What is this?
@@ -232,6 +232,7 @@ even approximately, in ASCII.
Date | Change
-----|-------
2.05, Apr 2022 | Fixed bug with empty metadata tags
2.04, Apr 2022 | Improved handling of UTF-8 BOMs
2.03, Jan 2022 | Fixed a buffer overrun bug
2.02, May 2020 | Updated XML parser

View File

@@ -3,7 +3,7 @@
.\" redistribute this software so long as all of the original files are
.\" included, and that this copyright notice is retained.
.\"
.TH epub2txt 1 "April 2022"
.TH epub2txt 1 "May 2022"
.SH NAME
epub2txt \- Extract text from EPUB documents
.SH SYNOPSIS

View File

@@ -89,14 +89,22 @@ static char *epub2txt_unescape_html (const char *s)
static void epub2txt_format_meta (const Epub2TxtOptions *options,
const char *key, const char *text)
{
char *ss = epub2txt_unescape_html (text);
char *s;
asprintf (&s, "%s: %s", key, ss);
char *error = NULL;
xhtml_utf8_to_stdout (s, options, &error);
if (error) free (error);
free (s);
free (ss);
// text ends up "null" here, if the meta tag had no content (which should
// not happen, but we don't want to crash if it does). I suppress all
// output in this case, but perhaps it would be better to print the
// metadata key, and the value "null", or "empty"? I can't really predict
// what a user would prefer to see.
if (text)
{
char *ss = epub2txt_unescape_html (text);
char *s;
asprintf (&s, "%s: %s", key, ss);
char *error = NULL;
xhtml_utf8_to_stdout (s, options, &error);
if (error) free (error);
free (s);
free (ss);
}
}