changeset 20:90e7020df08a

GSM7 string parsers accept new bypass-encoding escapes
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Feb 2021 03:44:59 +0000
parents 72a24b8538eb
children d4dc86195382
files libcommon/alpha_fromfile.c libcommon/gsm7_encode.c
diffstat 2 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libcommon/alpha_fromfile.c	Fri Feb 12 03:33:26 2021 +0000
+++ b/libcommon/alpha_fromfile.c	Fri Feb 12 03:44:59 2021 +0000
@@ -33,13 +33,20 @@
 			if (*cp == '\0')
 				goto unterm_qstring;
 			c = *cp++;
+			if (c >= '0' && c <= '7' && isxdigit(*cp)) {
+				c = ((c - '0') << 4) | decode_hex_digit(*cp++);
+				goto bypass_encoding;
+			}
 			switch (c) {
 			case 'n':
 				c = '\n';
-				break;
+				goto bypass_encoding;
 			case 'r':
 				c = '\r';
-				break;
+				goto bypass_encoding;
+			case 'e':
+				c = 0x1B;
+				goto bypass_encoding;
 			case '"':
 			case '\\':
 				break;
@@ -57,6 +64,7 @@
 				filename_for_errs, lineno_for_errs);
 			return(0);
 		}
+bypass_encoding:
 		if (c & 0x80)
 			nadd = 2;
 		else
--- a/libcommon/gsm7_encode.c	Fri Feb 12 03:33:26 2021 +0000
+++ b/libcommon/gsm7_encode.c	Fri Feb 12 03:44:59 2021 +0000
@@ -29,13 +29,20 @@
 				return(-1);
 			}
 			c = *cp++;
+			if (c >= '0' && c <= '7' && isxdigit(*cp)) {
+				c = ((c - '0') << 4) | decode_hex_digit(*cp++);
+				goto bypass_encoding;
+			}
 			switch (c) {
 			case 'n':
 				c = '\n';
-				break;
+				goto bypass_encoding;
 			case 'r':
 				c = '\r';
-				break;
+				goto bypass_encoding;
+			case 'e':
+				c = 0x1B;
+				goto bypass_encoding;
 			case '"':
 			case '\\':
 				break;
@@ -51,6 +58,7 @@
 	"error: character in alpha tag string cannot be encoded in GSM7\n");
 			return(-1);
 		}
+bypass_encoding:
 		if (c & 0x80)
 			nadd = 2;
 		else