Skip to content

[FIX] escape special characters ( < > & ) to HTML context #1703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGES.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -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)
-----------------
Expand Down
5 changes: 4 additions & 1 deletion src/lib_ccx/ccx_decoders_708_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/lib_ccx/ccx_encoders_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ccx_common_constants.h"
#include "ccx_common_structs.h"
#include "ccx_decoders_common.h"
#include "utility.h"

#include <assert.h>

Expand Down Expand Up @@ -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;
Expand Down
32 changes: 32 additions & 0 deletions src/lib_ccx/utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "&amp;";
else if (ascii_char == '<')
write = "&lt;";
else if (ascii_char == '>')
write = "&gt;";
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 */
Expand Down
2 changes: 2 additions & 0 deletions src/lib_ccx/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading