[[[
Fix issue #4263: svnrdump: E125005: Cannot accept non-LF line endings in
'svn:log' property

Fix to ensure that no "\r" characters are present in revision or node
props.

In the case of "\r\n" character sequences, the "\r" is removed.

In the case of "\r" characters which are not followed by "\n", the "\r"
is replaced by a "\n" character.

* subversion/svnrdump/svnrdump.h:
   (svn_rdump__normalize_prop): New function declaration.

* subversion/svnrdump/util.c:
   (svn_rdump__normalize_prop): New function to allow "svnrdump load" to
     use existing logic
   (svn_rdump__normalize_props): Refactored to move logic into
     svn_rdump__normalize_prop()

* subversion/svnrdump/load_editor.c:
   (set_revision_property): Added call to svn_rdump__normalize_prop()
   (set_node_property): Added call to svn_rdump__normalize_prop()

* subversion/tests/cmdline/svnrdump_tests.py:
   (copy_bad_line_endings_load): Removed "XFail" decorator

]]]
Index: subversion/tests/cmdline/svnrdump_tests.py
===================================================================
--- subversion/tests/cmdline/svnrdump_tests.py	(revision 1423235)
+++ subversion/tests/cmdline/svnrdump_tests.py	(working copy)
@@ -358,7 +358,6 @@ def copy_bad_line_endings_dump(sbox):
                 expected_dumpfile_name="copy-bad-line-endings.expected.dump",
                 bypass_prop_validation=True)
 
-@XFail()
 @Issue(4263)
 def copy_bad_line_endings_load(sbox):
   "load: inconsistent line endings in svn:* props"
Index: subversion/svnrdump/util.c
===================================================================
--- subversion/svnrdump/util.c	(revision 1423235)
+++ subversion/svnrdump/util.c	(working copy)
@@ -31,6 +31,25 @@
 
 
 svn_error_t *
+svn_rdump__normalize_prop(const char *name,
+                          const svn_string_t **value,
+                          apr_pool_t *result_pool)
+{
+  if (svn_prop_needs_translation(name))
+    {
+      const char *cstring;
+
+      SVN_ERR(svn_subst_translate_cstring2((*value)->data, &cstring,
+                                           "\n", TRUE,
+                                           NULL, FALSE,
+                                           result_pool));
+
+      *value = svn_string_create(cstring, result_pool);
+    }
+  return SVN_NO_ERROR;
+}
+
+svn_error_t *
 svn_rdump__normalize_props(apr_hash_t **normal_props,
                            apr_hash_t *props,
                            apr_pool_t *result_pool)
@@ -45,17 +64,9 @@ svn_rdump__normalize_props(apr_hash_t **normal_pro
       const char *key = svn__apr_hash_index_key(hi);
       const svn_string_t *value = svn__apr_hash_index_val(hi);
 
-      if (svn_prop_needs_translation(key))
-        {
-          const char *cstring;
+      SVN_ERR(svn_rdump__normalize_prop(key, &value,
+                                        result_pool));
 
-          SVN_ERR(svn_subst_translate_cstring2(value->data, &cstring,
-                                               "\n", TRUE,
-                                               NULL, FALSE,
-                                               result_pool));
-          value = svn_string_create(cstring, result_pool);
-        }
-
       apr_hash_set(*normal_props, key, APR_HASH_KEY_STRING, value);
     }
   return SVN_NO_ERROR;
Index: subversion/svnrdump/svnrdump.h
===================================================================
--- subversion/svnrdump/svnrdump.h	(revision 1423235)
+++ subversion/svnrdump/svnrdump.h	(working copy)
@@ -106,6 +106,20 @@ svn_rdump__normalize_props(apr_hash_t **normal_pro
                            apr_hash_t *props,
                            apr_pool_t *result_pool);
 
+/* Normalize the line ending style of a single property that "needs
+ * translation" (according to svn_prop_needs_translation(),
+ * currently all svn:* props) so that they contain only LF (\n) line endings.
+ * "\r" characters found mid-line are replaced with "\n".
+ * "\r\n" sequences are replaced with "\n"
+ *
+ * NAME is used to check that VALUE should be normalized, and if this is the
+ * case, VALUE is then normalized, allocated from RESULT_POOL
+ */
+svn_error_t *
+svn_rdump__normalize_prop(const char *name,
+                          const svn_string_t **value,
+                          apr_pool_t *result_pool);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
Index: subversion/svnrdump/load_editor.c
===================================================================
--- subversion/svnrdump/load_editor.c	(revision 1423235)
+++ subversion/svnrdump/load_editor.c	(working copy)
@@ -855,6 +855,8 @@ set_revision_property(void *baton,
 {
   struct revision_baton *rb = baton;
 
+  SVN_ERR(svn_rdump__normalize_prop(name, &value, rb->pool));
+  
   SVN_ERR(svn_repos__validate_prop(name, value, rb->pool));
 
   if (rb->rev > 0)
@@ -934,6 +936,8 @@ set_node_property(void *baton,
         }
     }
 
+  SVN_ERR(svn_rdump__normalize_prop(name, &value, pool));
+
   SVN_ERR(svn_repos__validate_prop(name, value, pool));
 
   switch (nb->kind)

Reply via email to