Index: subversion/bindings/java/javahl/native/org_tigris_subversion_javahl_Path.cpp =================================================================== --- subversion/bindings/java/javahl/native/org_tigris_subversion_javahl_Path.cpp (revision 0) +++ subversion/bindings/java/javahl/native/org_tigris_subversion_javahl_Path.cpp (revision 0) @@ -0,0 +1,38 @@ +/** + * @copyright + * ==================================================================== + * Copyright (c) 2006 CollabNet. All rights reserved. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://subversion.tigris.org/license-1.html. + * If newer versions of this license are posted there, you may use a + * newer version instead, at your option. + * + * This software consists of voluntary contributions made by many + * individuals. For exact contribution history, see the revision + * history and logs, available at http://subversion.tigris.org/. + * ==================================================================== + * @endcopyright + * + * @file org_tigris_subversion_javahl_Path.cpp + * @brief Implementation of the native methods in the Java class Path + */ +#include +#include "../include/org_tigris_subversion_javahl_Path.h" +#include "JNIUtil.h" +#include "JNIStackElement.h" +#include "JNIStringHolder.h" +#include "SVNPath.h" + +JNIEXPORT jboolean JNICALL Java_org_tigris_subversion_javahl_Path_isValid + (JNIEnv* env, jclass jthis, jstring jpath) +{ + JNIEntry(Path, isValid); + JNIStringHolder path(jpath); + if (JNIUtil::isExceptionThrown()) + { + return JNI_FALSE; + } + return SVNPath::isValid(path); +} Index: subversion/bindings/java/javahl/native/SVNPath.h =================================================================== --- subversion/bindings/java/javahl/native/SVNPath.h (revision 0) +++ subversion/bindings/java/javahl/native/SVNPath.h (revision 0) @@ -0,0 +1,38 @@ +/** + * @copyright + * ==================================================================== + * Copyright (c) 2006 CollabNet. All rights reserved. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://subversion.tigris.org/license-1.html. + * If newer versions of this license are posted there, you may use a + * newer version instead, at your option. + * + * This software consists of voluntary contributions made by many + * individuals. For exact contribution history, see the revision + * history and logs, available at http://subversion.tigris.org/. + * ==================================================================== + * @endcopyright + * + * @file SVNPath.h + * @brief Interface of the C++ class SVNPath. + */ + +#if !defined(AFX_SVNPATH_H__9AD95B26_47BF_4430_8217_20B87ACCE87B__INCLUDED_) +#define AFX_SVNPATH_H__9AD95B26_47BF_4430_8217_20B87ACCE87B__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 +#include + +class SVNPath +{ +public: + SVNPath(); + virtual ~SVNPath(); + static jboolean isValid(const char *path); +}; +// !defined(AFX_SVNPATH_H__9AD95B26_47BF_4430_8217_20B87ACCE87B__INCLUDED_) +#endif Index: subversion/bindings/java/javahl/native/SVNPath.cpp =================================================================== --- subversion/bindings/java/javahl/native/SVNPath.cpp (revision 0) +++ subversion/bindings/java/javahl/native/SVNPath.cpp (revision 0) @@ -0,0 +1,45 @@ +/** + * @copyright + * ==================================================================== + * Copyright (c) 2006 CollabNet. All rights reserved. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://subversion.tigris.org/license-1.html. + * If newer versions of this license are posted there, you may use a + * newer version instead, at your option. + * + * This software consists of voluntary contributions made by many + * individuals. For exact contribution history, see the revision + * history and logs, available at http://subversion.tigris.org/. + * ==================================================================== + * @endcopyright + */ + +#include +#include "SVNPath.h" +#include "Pool.h" +#include "svn_path.h" + +SVNPath::SVNPath() +{ +} + +SVNPath::~SVNPath() +{ +} + +jboolean SVNPath::isValid(const char *path) +{ + Pool requestPool; + svn_error_t *err = svn_path_check_valid(path, requestPool.pool()); + if (err == SVN_NO_ERROR) + { + return JNI_TRUE; + } + else + { + svn_error_clear(err); + return JNI_FALSE; + } +} Index: subversion/bindings/java/javahl/src/org/tigris/subversion/javahl/tests/BasicTests.java =================================================================== --- subversion/bindings/java/javahl/src/org/tigris/subversion/javahl/tests/BasicTests.java (revision 18975) +++ subversion/bindings/java/javahl/src/org/tigris/subversion/javahl/tests/BasicTests.java (working copy) @@ -96,6 +96,17 @@ } /** + * Tests Subversion path validation. + */ + public void testPathValidation() throws Throwable + { + final String path = "/etc/passwd"; + assertTrue("Path validation failed for path '" + path + '\'', + Path.isValid(path)); + // TODO: Add negative test. + } + + /** * test the basic SVNClient.checkout functionality * @throws Throwable */ Index: subversion/bindings/java/javahl/src/org/tigris/subversion/javahl/Path.java =================================================================== --- subversion/bindings/java/javahl/src/org/tigris/subversion/javahl/Path.java (revision 0) +++ subversion/bindings/java/javahl/src/org/tigris/subversion/javahl/Path.java (revision 0) @@ -0,0 +1,40 @@ +package org.tigris.subversion.javahl; + +/** + * @copyright + * ==================================================================== + * Copyright (c) 2006 CollabNet. All rights reserved. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://subversion.tigris.org/license-1.html. + * If newer versions of this license are posted there, you may use a + * newer version instead, at your option. + * + * This software consists of voluntary contributions made by many + * individuals. For exact contribution history, see the revision + * history and logs, available at http://subversion.tigris.org/. + * ==================================================================== + * @endcopyright + */ + +/** + * Subversion path validation and manipulation. + */ +public class Path +{ + /** + * Load the required native library. + */ + static + { + NativeResources.loadNativeLibrary(); + } + + /** + * A valid path is a UTF-8 string without any control characters. + * + * @return Whether Subversion can store the path in a repository. + */ + public static native boolean isValid(String path); +}