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