[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn: MIME type 'text/x-c++' ends with non-alphanumeric character

From: Stefan Sperling <stsp_at_elego.de>
Date: Sat, 26 Apr 2008 12:58:30 +0200

Thread moved to dev@

On Sat, Apr 26, 2008 at 10:24:45AM +0200, Alan Barrett wrote:
> On Fri, 25 Apr 2008, Andy Levy wrote:
> > On Fri, Apr 25, 2008 at 5:12 PM, Mark E. Hamilton <mhamilt_at_sandia.gov> wrote:
> > > $ svn propset --quiet svn:mime-type 'text/x-c++' --targets .svn_files
> > > svn: MIME type 'text/x-c++' ends with non-alphanumeric character
>
> If svn is complaining about that, I'd call it a bug. The syntax defined
> in RFC 1521 clearly says
>
> token := 1*<any (ASCII) CHAR except SPACE, CTLs,
> or tspecials>
>
> There's nothing about "must start and end with an alphanumeric character".
>
> > > 1. What is the correct mime-type for C++ files? Clearly 'text/plain' would
> > > suffice, but is there a more correct one?
> >
> > http://filext.com/file-extension/CPP shows several options:
>
> Sure, you could probably find something that works for whatever you
> want to do, and also works with svn. But you should be able to use
> "text/x-c++" without svn complaining. I suggest reporting this as a
> bug.

Would this be better?

Can anyone test if this breaks anything?
(There seem to be no mime-type-related unit tests...)

Index: subversion/libsvn_subr/validate.c
===================================================================
--- subversion/libsvn_subr/validate.c (revision 30791)
+++ subversion/libsvn_subr/validate.c (working copy)
@@ -41,6 +41,8 @@ svn_mime_type_validate(const char *mime_type, apr_
      only looking at the media type here. */
   const apr_size_t len = strcspn(mime_type, "; ");
   const char *const slash_pos = strchr(mime_type, '/');
+ int i;
+ const char *tspecials = "()<>@,;:\\\"/[]?="; /* see RFC 1521 */
 
   if (len == 0)
     return svn_error_createf
@@ -52,10 +54,20 @@ svn_mime_type_validate(const char *mime_type, apr_
       (SVN_ERR_BAD_MIME_TYPE, NULL,
        _("MIME type '%s' does not contain '/'"), mime_type);
 
- if (! apr_isalnum(mime_type[len - 1]))
- return svn_error_createf
- (SVN_ERR_BAD_MIME_TYPE, NULL,
- _("MIME type '%s' ends with non-alphanumeric character"), mime_type);
+ /* RFC 1521 says:
+ * subtype := token ; case-insensitive
+ * token := 1*<any (ASCII) CHAR except SPACE, CTLs, or tspecials> */
+ for (i = 0; i < len; i++)
+ {
+ if (! apr_isascii(mime_type[i])
+ || apr_iscntrl(mime_type[i])
+ || apr_isspace(mime_type[i])
+ || strchr(tspecials, mime_type[i]) != NULL)
+ return svn_error_createf
+ (SVN_ERR_BAD_MIME_TYPE, NULL,
+ _("MIME type '%s' contains invalid character '%c'"),
+ mime_type, mime_type[i]);
+ }
 
   return SVN_NO_ERROR;
 }

-- 
Stefan Sperling <stsp_at_elego.de>                    Software Monkey
 
German law requires the following banner :(
elego Software Solutions GmbH                            HRB 77719
Gustav-Meyer-Allee 25, Gebaeude 12        Tel:  +49 30 23 45 86 96 
13355 Berlin                              Fax:  +49 30 23 45 86 95
http://www.elego.de                               CEO: Olaf Wagner
 
Store password unencrypted (yes/no)? No

  • application/pgp-signature attachment: stored
Received on 2008-04-26 12:57:34 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.