Skip to content

Fix Issue#1235: Sanitize XML comment to prevent invalid token errors #1642

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
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
27 changes: 26 additions & 1 deletion src/lib_ccx/ccx_encoders_spupng.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,32 @@ void write_sputag_close(struct spupng_t *sp)
}
void write_spucomment(struct spupng_t *sp, const char *str)
{
fprintf(sp->fpxml, "<!--\n%s\n-->\n", str);
fprintf(sp->fpxml, "<!--\n");

const char *p = str;
const char *last_safe_pos = str; // Track the last safe position to flush

while (*p) {

if (*p == '-' && *(p + 1) == '-') {

if (p > last_safe_pos) {
fwrite(last_safe_pos, 1, p - last_safe_pos, sp->fpxml);
}

fputc('-', sp->fpxml);
p += 2;
last_safe_pos = p;
} else {
p++;
}
}

if (p > last_safe_pos) {
fwrite(last_safe_pos, 1, p - last_safe_pos, sp->fpxml);
}

fprintf(sp->fpxml, "\n-->\n");
}

char *get_spupng_filename(void *ctx)
Expand Down
Loading