Make sure shellescape() does not mangle UTF-8 characters.

This commit is contained in:
Dianne Skoll
2024-04-22 09:50:17 -04:00
parent c03a95ad94
commit 67ae95a464
3 changed files with 18 additions and 4 deletions

View File

@@ -165,11 +165,15 @@ int _private_sub_overflow(int a, int b)
int
ShellEscape(char const *in, DynamicBuffer *out)
{
while(*in) {
if (!strchr(DontEscapeMe, *in)) {
if (DBufPutc(out, '\\') != OK) return E_NO_MEM;
unsigned char const *i = (unsigned char const *) in;
while(*i) {
/* Don't escape chars with high bit set. That will mangle UTF-8 */
if (! (*i & 0x80) ) {
if (!strchr(DontEscapeMe, *i)) {
if (DBufPutc(out, '\\') != OK) return E_NO_MEM;
}
}
if (DBufPutc(out, *in++) != OK) return E_NO_MEM;
if (DBufPutc(out, *i++) != OK) return E_NO_MEM;
}
return OK;
}

View File

@@ -4972,6 +4972,13 @@ trigtime() => 16:00
../tests/test.rem(940): Trig = Tuesday, 19 February, 1991 AT 10:00 DURATION 16:00
../tests/test.rem(940): Trig = Tuesday, 19 February, 1991 AT 10:00 DURATION 16:00
# Make sure shellescape does not mangle UTF-8 characters
msg [shellescape("😆")]
../tests/test.rem(943): Trig = Saturday, 16 February, 1991
shellescape("😆") => "😆"
😆
# Don't want Remind to queue reminders
EXIT

View File

@@ -939,6 +939,9 @@ REM Tue AT 10:00 DURATION [$Tt] MSG blort
REM Tue AT 16:00 MSG blort
REM Tue AT 10:00 DURATION [trigtime()] MSG blort
# Make sure shellescape does not mangle UTF-8 characters
msg [shellescape("😆")]
# Don't want Remind to queue reminders
EXIT