mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Improved HTML entity handling
Now handles quot and frasl as suggested by Ian Jeffray and also allocates memory properly, preventing SIGSEGV for Code 128 full of ampersands.
This commit is contained in:
parent
7bcc0252a9
commit
0fe9051324
@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2009-2018 Robin Stuart <rstuart114@gmail.com>
|
||||
Copyright (C) 2009-2019 Robin Stuart <rstuart114@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@ -41,55 +41,48 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
void make_html_friendly(unsigned char * string, unsigned char * html_version) {
|
||||
/* Convert text into HTML friendly format by doing the following:
|
||||
* > becomes >
|
||||
* < becomes <
|
||||
* & becomes &
|
||||
*/
|
||||
void make_html_friendly(unsigned char * string, char * html_version) {
|
||||
/* Converts text to use HTML entity codes */
|
||||
|
||||
int i, html_pos;
|
||||
int i, html_pos;
|
||||
|
||||
html_pos = 0;
|
||||
html_version[html_pos] = '\0';
|
||||
html_pos = 0;
|
||||
html_version[html_pos] = '\0';
|
||||
|
||||
for (i = 0; i < ustrlen(string); i++) {
|
||||
switch(string[i]) {
|
||||
case '>':
|
||||
html_version[html_pos] = '&';
|
||||
html_version[html_pos + 1] = 'g';
|
||||
html_version[html_pos + 2] = 't';
|
||||
html_version[html_pos + 3] = ';';
|
||||
for (i = 0; i < ustrlen(string); i++) {
|
||||
switch(string[i]) {
|
||||
case '>':
|
||||
strcat(html_version, ">");
|
||||
html_pos += 4;
|
||||
html_version[html_pos] = '\0';
|
||||
break;
|
||||
break;
|
||||
|
||||
case '<':
|
||||
html_version[html_pos] = '&';
|
||||
html_version[html_pos + 1] = 'l';
|
||||
html_version[html_pos + 2] = 't';
|
||||
html_version[html_pos + 3] = ';';
|
||||
case '<':
|
||||
strcat(html_version, "<");
|
||||
html_pos += 4;
|
||||
html_version[html_pos] = '\0';
|
||||
break;
|
||||
break;
|
||||
|
||||
case '&':
|
||||
html_version[html_pos] = '&';
|
||||
html_version[html_pos + 1] = 'a';
|
||||
html_version[html_pos + 2] = 'm';
|
||||
html_version[html_pos + 3] = 'p';
|
||||
html_version[html_pos + 4] = ';';
|
||||
case '&':
|
||||
strcat(html_version, "&");
|
||||
html_pos += 5;
|
||||
html_version[html_pos] = '\0';
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
case '"':
|
||||
strcat(html_version, """);
|
||||
html_pos += 6;
|
||||
break;
|
||||
|
||||
case '/':
|
||||
strcat(html_version, "⁄");
|
||||
html_pos += 7;
|
||||
break;
|
||||
|
||||
default:
|
||||
html_version[html_pos] = string[i];
|
||||
html_pos++;
|
||||
html_version[html_pos] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int svg_plot(struct zint_symbol *symbol) {
|
||||
@ -104,10 +97,24 @@ int svg_plot(struct zint_symbol *symbol) {
|
||||
struct zint_vector_circle *circle;
|
||||
struct zint_vector_string *string;
|
||||
|
||||
int html_len = strlen((char *)symbol->text) + 1;
|
||||
|
||||
for (int i = 0; i < strlen((char *)symbol->text); i++) {
|
||||
switch(symbol->text[i]) {
|
||||
case '>':
|
||||
case '<':
|
||||
case '"':
|
||||
case '&':
|
||||
case '/':
|
||||
html_len += 7;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef _MSC_VER
|
||||
unsigned char html_string[200];
|
||||
char html_string[html_len];
|
||||
#else
|
||||
unsigned char* html_string = (unsigned char*) _alloca(200);
|
||||
char* html_string = (unsigned char*) _alloca(html_len);
|
||||
#endif
|
||||
|
||||
/* Check for no created vector set */
|
||||
@ -139,7 +146,6 @@ int svg_plot(struct zint_symbol *symbol) {
|
||||
|
||||
fprintf(fsvg, " <rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" fill=\"#%s\" />\n", (int) ceil(symbol->vector->width), (int) ceil(symbol->vector->height), symbol->bgcolour);
|
||||
|
||||
|
||||
rect = symbol->vector->rectangles;
|
||||
while (rect) {
|
||||
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\" />\n", rect->x, rect->y, rect->width, rect->height);
|
||||
|
Loading…
Reference in New Issue
Block a user