Backport fix for issue #4340, "fs layer should reject filenames with
trailing \n", to the 1.7.x-issue4340 branch.

Merge r1461562 and r1461580 from trunk, resolving a text conflict
with the former revision, and a tree conflict with the latter revision.

* subversion/libsvn_fs/editor.c: This file doesn't exist in 1.7.x,
   so this change on trunk doesn't apply.

* subversion/libsvn_fs/fs-loader.c: Fix a text conflict caused by the
   existence of additional new tests in trunk. Tweak the test to not
   rely on SVN_TEST_ASSERT_ERROR which doesn't exist in 1.7.x.


git-svn-id: https://svn.apache.org/repos/asf/subversion/branches/1.7.x-issue4340@1461592 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/subversion/libsvn_fs/fs-loader.c b/subversion/libsvn_fs/fs-loader.c
index e9db910..2ea1c06 100644
--- a/subversion/libsvn_fs/fs-loader.c
+++ b/subversion/libsvn_fs/fs-loader.c
@@ -367,6 +367,9 @@
                                path);
     }
 
+  /* No control characters (see issue #4340). */
+  SVN_ERR(svn_path_check_valid(path, pool));
+
   /* That's good enough. */
   return SVN_NO_ERROR;
 }
diff --git a/subversion/tests/libsvn_fs/fs-test.c b/subversion/tests/libsvn_fs/fs-test.c
index 6f4d5db..505410e 100644
--- a/subversion/tests/libsvn_fs/fs-test.c
+++ b/subversion/tests/libsvn_fs/fs-test.c
@@ -4799,6 +4799,47 @@
   return SVN_NO_ERROR;
 }
 
+/* Issue 4340, "fs layer should reject filenames with trailing \n" */
+static svn_error_t *
+filename_trailing_newline(const svn_test_opts_t *opts,
+                          apr_pool_t *pool)
+{
+  apr_pool_t *subpool = svn_pool_create(pool);
+  svn_fs_t *fs;
+  svn_fs_txn_t *txn;
+  svn_fs_root_t *txn_root, *root;
+  svn_revnum_t youngest_rev = 0;
+  svn_error_t *err;
+
+  SVN_ERR(svn_test__create_fs(&fs, "test-filename-trailing-newline",
+                              opts, pool));
+
+/* ------------------------------------------------------------------------ */
+  /* Revision 1:  Add a directory /foo  */
+  SVN_ERR(svn_fs_begin_txn(&txn, fs, youngest_rev, subpool));
+  SVN_ERR(svn_fs_txn_root(&txn_root, txn, subpool));
+  SVN_ERR(svn_fs_make_dir(txn_root, "/foo", subpool));
+  SVN_ERR(svn_fs_commit_txn(NULL, &youngest_rev, txn, subpool));
+  SVN_TEST_ASSERT(SVN_IS_VALID_REVNUM(youngest_rev));
+  svn_pool_clear(subpool);
+
+  /* Attempt to copy /foo to "/bar\n". This should fail. */
+  SVN_ERR(svn_fs_begin_txn(&txn, fs, youngest_rev, subpool));
+  SVN_ERR(svn_fs_txn_root(&txn_root, txn, subpool));
+  SVN_ERR(svn_fs_revision_root(&root, fs, youngest_rev, subpool));
+  err = svn_fs_copy(root, "/foo", txn_root, "/bar\n", subpool);
+  SVN_TEST_ASSERT(err && err->apr_err == SVN_ERR_FS_PATH_SYNTAX);
+  svn_error_clear(err);
+
+  /* Attempt to create a file /foo/baz\n. This should fail. */
+  err = svn_fs_make_file(txn_root, "/foo/baz\n", subpool);
+  SVN_TEST_ASSERT(err && err->apr_err == SVN_ERR_FS_PATH_SYNTAX);
+  svn_error_clear(err);
+
+  return SVN_NO_ERROR;
+}
+
+
 /* ------------------------------------------------------------------------ */
 
 /* The test table.  */
@@ -4878,5 +4919,7 @@
                        "test svn_fs_node_origin_rev"),
     SVN_TEST_OPTS_PASS(small_file_integrity,
                        "create and modify small file"),
+    SVN_TEST_OPTS_PASS(filename_trailing_newline,
+                       "filenames with trailing \\n should be rejected"),
     SVN_TEST_NULL
   };