0233e9
diff --git a/magic/Magdir/filesystems b/magic/Magdir/filesystems
0233e9
index a2c2966..ecfa6c2 100644
0233e9
--- a/magic/Magdir/filesystems
0233e9
+++ b/magic/Magdir/filesystems
0233e9
@@ -1251,7 +1251,7 @@
0233e9
 >>38917	byte     >0x33      (unknown version, ID 0x%X)
0233e9
 >>38917	byte     <0x31      (unknown version, ID 0x%X)
0233e9
 # "application id" which appears to be used as a volume label
0233e9
->32808	string    >\0       '%s'
0233e9
+>32808	string/T  >\0       '%s'
0233e9
 >34816	string    \000CD001\001EL\ TORITO\ SPECIFICATION    (bootable)
0233e9
 37633	string    CD001     ISO 9660 CD-ROM filesystem data (raw 2352 byte sectors)
0233e9
 !:mime	application/x-iso9660-image
0233e9
diff --git a/src/apprentice.c b/src/apprentice.c
0233e9
index 0490642..6dd8381 100644
0233e9
--- a/src/apprentice.c
0233e9
+++ b/src/apprentice.c
0233e9
@@ -1452,6 +1452,9 @@ parse(struct magic_set *ms, struct magic_entry **mentryp, uint32_t *nmentryp,
0233e9
 						goto bad;
0233e9
 					m->str_flags |= PSTRING_LENGTH_INCLUDES_ITSELF;
0233e9
 					break;
0233e9
+				case CHAR_TRIM:
0233e9
+					m->str_flags |= STRING_TRIM;
0233e9
+					break;
0233e9
 				default:
0233e9
 				bad:
0233e9
 					if (ms->flags & MAGIC_CHECK)
0233e9
diff --git a/src/file.h b/src/file.h
0233e9
index e02009f..1b5f53f 100644
0233e9
--- a/src/file.h
0233e9
+++ b/src/file.h
0233e9
@@ -307,6 +307,7 @@ struct magic {
0233e9
 #define PSTRING_LEN	\
0233e9
     (PSTRING_1_BE|PSTRING_2_LE|PSTRING_2_BE|PSTRING_4_LE|PSTRING_4_BE)
0233e9
 #define PSTRING_LENGTH_INCLUDES_ITSELF		BIT(12)
0233e9
+#define STRING_TRIM             BIT(13)
0233e9
 #define CHAR_COMPACT_WHITESPACE			'W'
0233e9
 #define CHAR_COMPACT_OPTIONAL_WHITESPACE	'w'
0233e9
 #define CHAR_IGNORE_LOWERCASE			'c'
0233e9
@@ -321,6 +322,7 @@ struct magic {
0233e9
 #define CHAR_PSTRING_4_BE			'L'
0233e9
 #define CHAR_PSTRING_4_LE			'l'
0233e9
 #define CHAR_PSTRING_LENGTH_INCLUDES_ITSELF     'J'
0233e9
+#define CHAR_TRIM               'T'
0233e9
 #define STRING_IGNORE_CASE		(STRING_IGNORE_LOWERCASE|STRING_IGNORE_UPPERCASE)
0233e9
 #define STRING_DEFAULT_RANGE		100
0233e9
 
0233e9
diff --git a/src/softmagic.c b/src/softmagic.c
0233e9
index 8d08cad..f084edd 100644
0233e9
--- a/src/softmagic.c
0233e9
+++ b/src/softmagic.c
0233e9
@@ -451,11 +451,30 @@ mprint(struct magic_set *ms, struct magic *m)
0233e9
 			t = ms->offset + m->vallen;
0233e9
 		}
0233e9
 		else {
0233e9
+			char *str = p->s;
0233e9
+
0233e9
+			/* compute t before we mangle the string? */
0233e9
+			t = ms->offset + strlen(str);
0233e9
+
0233e9
 			if (*m->value.s == '\0')
0233e9
-				p->s[strcspn(p->s, "\n")] = '\0';
0233e9
-			if (file_printf(ms, m->desc, p->s) == -1)
0233e9
+				str[strcspn(str, "\n")] = '\0';
0233e9
+
0233e9
+			if (m->str_flags & STRING_TRIM) {
0233e9
+				char *last;
0233e9
+				while (isspace((unsigned char)*str))
0233e9
+					str++;
0233e9
+				last = str;
0233e9
+				while (*last)
0233e9
+					last++;
0233e9
+				--last;
0233e9
+				while (isspace((unsigned char)*last))
0233e9
+					last--;
0233e9
+				*++last = '\0';
0233e9
+			}
0233e9
+
0233e9
+			if (file_printf(ms, m->desc, str) == -1)
0233e9
 				return -1;
0233e9
-			t = ms->offset + strlen(p->s);
0233e9
+
0233e9
 			if (m->type == FILE_PSTRING)
0233e9
 				t += file_pstring_length_size(m);
0233e9
 		}