diff --git a/docs/CHANGES.TXT b/docs/CHANGES.TXT index 4503d0f43..b7c23112d 100644 --- a/docs/CHANGES.TXT +++ b/docs/CHANGES.TXT @@ -41,6 +41,7 @@ - Fix: Resolve compile-time error about implicit declarations (#1646) - Fix: fatal out of memory error extracting from a VOB PS - Fix: Unit Test Rust failing due to changes in Rust Version 1.86.0 +- Fix: escape special characters ( < > & ) to HTML context 0.94 (2021-12-14) ----------------- diff --git a/src/lib_ccx/ccx_decoders_708_output.c b/src/lib_ccx/ccx_decoders_708_output.c index 5697ad242..09c16e2cc 100644 --- a/src/lib_ccx/ccx_decoders_708_output.c +++ b/src/lib_ccx/ccx_decoders_708_output.c @@ -156,7 +156,10 @@ void dtvcc_write_row(dtvcc_writer_ctx *writer, dtvcc_service_decoder *decoder, i } else { - size_t size = write_utf16_char(tv->chars[row_index][i].sym, buf + buf_len); + unsigned char *buffer = buf + buf_len; + size_t size = write_utf16_char(tv->chars[row_index][i].sym, buffer); + if (size == 1) + size = ascii_to_html(*buffer, buffer); buf_len += size; } } diff --git a/src/lib_ccx/ccx_encoders_helpers.c b/src/lib_ccx/ccx_encoders_helpers.c index 00f96b45b..00f573b33 100644 --- a/src/lib_ccx/ccx_encoders_helpers.c +++ b/src/lib_ccx/ccx_encoders_helpers.c @@ -3,6 +3,7 @@ #include "ccx_common_constants.h" #include "ccx_common_structs.h" #include "ccx_decoders_common.h" +#include "utility.h" #include @@ -350,14 +351,22 @@ unsigned get_decoder_line_encoded(struct encoder_ctx *ctx, unsigned char *buffer { case CCX_ENC_UTF_8: bytes = get_char_in_utf_8(buffer, line[i]); + if (bytes == 1) + bytes = ascii_to_html(*buffer, buffer); break; case CCX_ENC_LATIN_1: get_char_in_latin_1(buffer, line[i]); - bytes = 1; + bytes = ascii_to_html(*buffer, buffer); break; case CCX_ENC_UNICODE: get_char_in_unicode(buffer, line[i]); - bytes = 2; + if (buffer[1] == 0) + { + bytes = ascii_to_html(*buffer, buffer); + bytes = ascii_to_unicode(buffer, bytes, buffer); + } + else + bytes = 2; break; case CCX_ENC_ASCII: // Consider to remove ASCII encoding or write get_char_in_ascii(...) break; diff --git a/src/lib_ccx/utility.c b/src/lib_ccx/utility.c index 9714a1627..2d392d0f1 100644 --- a/src/lib_ccx/utility.c +++ b/src/lib_ccx/utility.c @@ -662,6 +662,38 @@ size_t utf16_to_utf8(unsigned short utf16_char, unsigned char *out) return 0; } +size_t ascii_to_html(unsigned char ascii_char, unsigned char *out) +{ + unsigned char *write = NULL; + if (ascii_char == '&') + write = "&"; + else if (ascii_char == '<') + write = "<"; + else if (ascii_char == '>') + write = ">"; + if (write != NULL) + { + strcpy(out, write); + return strlen(write); + } + else + { + out[0] = ascii_char; + return 1; + } + return 0; +} + +size_t ascii_to_unicode(unsigned char *ascii_char_buf, int ascii_char_len, unsigned char *out) +{ + for (int i = ascii_char_len - 1; i >= 0; i--) + { + out[i * 2] = ascii_char_buf[i]; + out[i * 2 + 1] = 0; + } + return ascii_char_len * 2; +} + LLONG change_timebase(LLONG val, struct ccx_rational cur_tb, struct ccx_rational dest_tb) { /* val = (value * current timebase) / destination timebase */ diff --git a/src/lib_ccx/utility.h b/src/lib_ccx/utility.h index 6fc6eafa1..6a6e65a7b 100644 --- a/src/lib_ccx/utility.h +++ b/src/lib_ccx/utility.h @@ -45,6 +45,8 @@ const char *get_file_extension(const enum ccx_output_format write_format); char *create_outfilename(const char *basename, const char *suffix, const char *extension); int verify_crc32(uint8_t *buf, int len); size_t utf16_to_utf8(unsigned short utf16_char, unsigned char *out); +size_t ascii_to_html(unsigned char ascii_char, unsigned char *out); +size_t ascii_to_unicode(unsigned char *ascii_char_buf, int ascii_char_len, unsigned char *out); LLONG change_timebase(LLONG val, struct ccx_rational cur_tb, struct ccx_rational dest_tb); char *str_reallocncat(char *dst, char *src);