You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by sv...@apache.org on 2013/07/09 06:00:43 UTC

svn commit: r1501074 - in /subversion/branches/1.8.x: ./ STATUS subversion/libsvn_subr/config_file.c subversion/tests/libsvn_subr/config-test.c

Author: svn-role
Date: Tue Jul  9 04:00:43 2013
New Revision: 1501074

URL: http://svn.apache.org/r1501074
Log:
Merge the r1499100 group from trunk:

 * r1499100, r1499483, r1499492, r1499496, r1499498
   Allow configuration files with an UTF-8 Byte Order Mark.
   Justification:
     Make it easier for users, particularly those on Windows using notepad,
     which will only save UTF-8 encoded text files with a BOM.
   Votes:
     +1: breser, stsp, danielsh

Modified:
    subversion/branches/1.8.x/   (props changed)
    subversion/branches/1.8.x/STATUS
    subversion/branches/1.8.x/subversion/libsvn_subr/config_file.c
    subversion/branches/1.8.x/subversion/tests/libsvn_subr/config-test.c

Propchange: subversion/branches/1.8.x/
------------------------------------------------------------------------------
  Merged /subversion/trunk:r1499100,1499483,1499492,1499496,1499498

Modified: subversion/branches/1.8.x/STATUS
URL: http://svn.apache.org/viewvc/subversion/branches/1.8.x/STATUS?rev=1501074&r1=1501073&r2=1501074&view=diff
==============================================================================
--- subversion/branches/1.8.x/STATUS (original)
+++ subversion/branches/1.8.x/STATUS Tue Jul  9 04:00:43 2013
@@ -120,14 +120,6 @@ Veto-blocked changes:
 Approved changes:
 =================
 
- * r1499100, r1499483, r1499492, r1499496, r1499498
-   Allow configuration files with an UTF-8 Byte Order Mark.
-   Justification:
-     Make it easier for users, particularly those on Windows using notepad,
-     which will only save UTF-8 encoded text files with a BOM.
-   Votes:
-     +1: breser, stsp, danielsh
-
  * ^/subversion/branches/1.8.x-r1495063
    r1495806, r1495985
    Fix crash in FSFS DAG caching code on strict-alignment architectures.

Modified: subversion/branches/1.8.x/subversion/libsvn_subr/config_file.c
URL: http://svn.apache.org/viewvc/subversion/branches/1.8.x/subversion/libsvn_subr/config_file.c?rev=1501074&r1=1501073&r2=1501074&view=diff
==============================================================================
--- subversion/branches/1.8.x/subversion/libsvn_subr/config_file.c (original)
+++ subversion/branches/1.8.x/subversion/libsvn_subr/config_file.c Tue Jul  9 04:00:43 2013
@@ -94,7 +94,7 @@ parser_getc(parse_context_t *ctx, int *c
         }
       else if (ctx->buffer_pos < ctx->buffer_size)
         {
-          *c = ctx->parser_buffer[ctx->buffer_pos];
+          *c = (unsigned char)ctx->parser_buffer[ctx->buffer_pos];
           ctx->buffer_pos++;
         }
       else
@@ -107,7 +107,7 @@ parser_getc(parse_context_t *ctx, int *c
 
           if (ctx->buffer_pos < ctx->buffer_size)
             {
-              *c = ctx->parser_buffer[ctx->buffer_pos];
+              *c = (unsigned char)ctx->parser_buffer[ctx->buffer_pos];
               ctx->buffer_pos++;
             }
           else
@@ -131,7 +131,7 @@ parser_getc_plain(parse_context_t *ctx, 
 {
   if (ctx->buffer_pos < ctx->buffer_size)
     {
-      *c = ctx->parser_buffer[ctx->buffer_pos];
+      *c = (unsigned char)ctx->parser_buffer[ctx->buffer_pos];
       ctx->buffer_pos++;
 
       return SVN_NO_ERROR;
@@ -189,6 +189,32 @@ skip_to_eoln(parse_context_t *ctx, int *
   return SVN_NO_ERROR;
 }
 
+/* Skip a UTF-8 Byte Order Mark if found. */
+static APR_INLINE svn_error_t *
+skip_bom(parse_context_t *ctx)
+{
+  int ch;
+
+  SVN_ERR(parser_getc(ctx, &ch));
+  if (ch == 0xEF)
+    {
+      const unsigned char *buf = (unsigned char *)ctx->parser_buffer;
+      /* This makes assumptions about the implementation of parser_getc and
+       * the use of skip_bom.  Specifically that parser_getc() will get all
+       * of the BOM characters into the parse_context_t buffer.  This can
+       * safely be assumed as long as we only try to use skip_bom() at the
+       * start of the stream and the buffer is longer than 3 characters. */
+      SVN_ERR_ASSERT(ctx->buffer_size > ctx->buffer_pos + 1);
+      if (buf[ctx->buffer_pos] == 0xBB && buf[ctx->buffer_pos + 1] == 0xBF)
+        ctx->buffer_pos += 2;
+      else
+        SVN_ERR(parser_ungetc(ctx, ch));
+    }
+  else
+    SVN_ERR(parser_ungetc(ctx, ch));
+
+  return SVN_NO_ERROR;
+}
 
 /* Parse a single option value */
 static svn_error_t *
@@ -450,6 +476,8 @@ svn_config__parse_stream(svn_config_t *c
   ctx->buffer_pos = 0;
   ctx->buffer_size = 0;
 
+  SVN_ERR(skip_bom(ctx));
+
   do
     {
       SVN_ERR(skip_whitespace(ctx, &ch, &count));

Modified: subversion/branches/1.8.x/subversion/tests/libsvn_subr/config-test.c
URL: http://svn.apache.org/viewvc/subversion/branches/1.8.x/subversion/tests/libsvn_subr/config-test.c?rev=1501074&r1=1501073&r2=1501074&view=diff
==============================================================================
--- subversion/branches/1.8.x/subversion/tests/libsvn_subr/config-test.c (original)
+++ subversion/branches/1.8.x/subversion/tests/libsvn_subr/config-test.c Tue Jul  9 04:00:43 2013
@@ -336,6 +336,22 @@ test_stream_interface(apr_pool_t *pool)
   return SVN_NO_ERROR;
 }
 
+static svn_error_t *
+test_ignore_bom(apr_pool_t *pool)
+{
+  svn_config_t *cfg;
+  svn_string_t *cfg_string = svn_string_create("\xEF\xBB\xBF[s1]\nfoo=bar\n",
+                                               pool);
+  svn_stream_t *stream = svn_stream_from_string(cfg_string, pool);
+
+  SVN_ERR(svn_config_parse(&cfg, stream, TRUE, TRUE, pool));
+
+  if (! svn_config_has_section(cfg, "s1"))
+    return fail(pool, "failed to find section s1");
+
+  return SVN_NO_ERROR;
+}
+
 /*
    ====================================================================
    If you add a new test to this file, update this array.
@@ -359,5 +375,6 @@ struct svn_test_descriptor_t test_funcs[
                    "test case-sensitive option name lookup"),
     SVN_TEST_PASS2(test_stream_interface,
                    "test svn_config_parse"),
+    SVN_TEST_PASS2(test_ignore_bom, "test parsing config file with BOM"),
     SVN_TEST_NULL
   };