You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by br...@apache.org on 2013/07/03 19:42:42 UTC

svn commit: r1499496 - in /subversion/trunk/subversion: libsvn_subr/config_file.c tests/libsvn_subr/config-test.c

Author: breser
Date: Wed Jul  3 17:42:42 2013
New Revision: 1499496

URL: http://svn.apache.org/r1499496
Log:
Allow config files to have a UTF-8 BOM at the start.

* subversion/libsvn_subr/config_file.c
  (skip_bom): New function to skip a UTF-8 BOM.
  (svn_config__parse_stream): Call skip_bom() at start of parsing.

* subversion/tests/libsvn_subr/config-test.c
  (test_funcs): Mark test_ignore_bom as passing.

Modified:
    subversion/trunk/subversion/libsvn_subr/config_file.c
    subversion/trunk/subversion/tests/libsvn_subr/config-test.c

Modified: subversion/trunk/subversion/libsvn_subr/config_file.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/config_file.c?rev=1499496&r1=1499495&r2=1499496&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/config_file.c (original)
+++ subversion/trunk/subversion/libsvn_subr/config_file.c Wed Jul  3 17:42:42 2013
@@ -189,6 +189,39 @@ 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 *
@@ -454,6 +487,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/trunk/subversion/tests/libsvn_subr/config-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/config-test.c?rev=1499496&r1=1499495&r2=1499496&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/config-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/config-test.c Wed Jul  3 17:42:42 2013
@@ -375,6 +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_XFAIL2(test_ignore_bom, "test parsing config file with BOM"),
+    SVN_TEST_PASS2(test_ignore_bom, "test parsing config file with BOM"),
     SVN_TEST_NULL
   };