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