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/11/25 11:10:26 UTC

svn commit: r1545205 - in /subversion/trunk/subversion/bindings/javahl: native/org_apache_subversion_javahl_util_SubstLib.cpp tests/org/apache/subversion/javahl/UtilTests.java

Author: brane
Date: Mon Nov 25 10:10:26 2013
New Revision: 1545205

URL: http://svn.apache.org/r1545205
Log:
Fixed a bug JavaHL stream translation utilility, where keywords were
not contracted as expected when given a keywords map with null values.

[in subversion/bindings/javahl]
* native/org_apache_subversion_javahl_util_SubstLib.cpp
  (KeywordHashBuilder::m_empty): New member; an empty svn_string_t.
  (KeywordHashBuilder::KeywordHashBuilder): Initialize m_empty.
  (KeywordHashBuilder::operator()): Insert an empty string into
   the keywords hash if the value in the map was null. Before this
   change, a NULL string would be inserted, which apr_hash_map
   interprets as a deletion.

* tests/org/apache/subversion/javahl/UtilTests.java
  (UtilTests.testTranslateStream): Test keyword contraction with
   null values in the keywords map, and irrelevant values for the
   keywords builder parameters in the short-circuit overloads.

Modified:
    subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_SubstLib.cpp
    subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/UtilTests.java

Modified: subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_SubstLib.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_SubstLib.cpp?rev=1545205&r1=1545204&r2=1545205&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_SubstLib.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_SubstLib.cpp Mon Nov 25 10:10:26 2013
@@ -86,15 +86,21 @@ class KeywordHashBuilder
 public:
   explicit KeywordHashBuilder(const SVN::Pool& pool)
     : m_pool(pool),
-      m_hash(apr_hash_make(pool.getPool()))
+      m_hash(apr_hash_make(pool.getPool())),
+      m_empty(svn_string_create_empty(pool.getPool()))
     {}
 
   void operator()(const std::string& key, const Java::ByteArray& value)
     {
       const char* const safe_key =
         apr_pstrmemdup(m_pool.getPool(), key.c_str(), key.size() + 1);
-      Java::ByteArray::Contents val(value);
-      apr_hash_set(m_hash, safe_key, key.size(), val.get_string(m_pool));
+      if (!value.get())
+        apr_hash_set(m_hash, safe_key, key.size(), m_empty);
+      else
+        {
+          Java::ByteArray::Contents val(value);
+          apr_hash_set(m_hash, safe_key, key.size(), val.get_string(m_pool));
+        }
     }
 
   apr_hash_t* get() const
@@ -105,6 +111,7 @@ public:
 private:
   const SVN::Pool& m_pool;
   apr_hash_t* const m_hash;
+  svn_string_t* const m_empty;
 };
 
 inline apr_hash_t*

Modified: subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/UtilTests.java
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/UtilTests.java?rev=1545205&r1=1545204&r2=1545205&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/UtilTests.java (original)
+++ subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/UtilTests.java Mon Nov 25 10:10:26 2013
@@ -39,6 +39,7 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.HashMap;
 
 /**
  * Tests the JavaHL SVNUtil APIs.
@@ -427,8 +428,12 @@ public class UtilTests extends SVNTests
         final Map<String, byte[]> keywords =
             SVNUtil.buildKeywords(keywordsValue, 42, "http://a/b/c",
                                   "http://a", new Date(1), "X");
+        final Map<String, byte[]> null_keywords = new HashMap<String, byte[]>();
         byte[] buffer = new byte[1024];
 
+        for (Map.Entry<String, byte[]> e : keywords.entrySet())
+            null_keywords.put(e.getKey(), null);
+
         // InputStream; expand
         InputStream testin = null;
         try {
@@ -473,7 +478,7 @@ public class UtilTests extends SVNTests
         try {
             testin = SVNUtil.translateStream(
                          new ByteArrayInputStream(contentsExpanded),
-                         SVNUtil.EOL_LF, true, keywords, false);
+                         SVNUtil.EOL_LF, true, null_keywords, false);
             final int size = testin.read(buffer);
             testin.close();
             testin = null;
@@ -492,8 +497,7 @@ public class UtilTests extends SVNTests
             testin = SVNUtil.translateStream(
                          new ByteArrayInputStream(contentsExpanded),
                          SVNUtil.EOL_LF, true, false,
-                         keywordsValue, 42, "http://a/b/c",
-                         "http://a", new Date(1), "X");
+                         keywordsValue, 0, "", "", new Date(1), "");
             final int size = testin.read(buffer);
             testin.close();
             testin = null;
@@ -551,7 +555,7 @@ public class UtilTests extends SVNTests
         try {
             ByteArrayOutputStream result = new ByteArrayOutputStream();
             testout = SVNUtil.translateStream(
-                         result, SVNUtil.EOL_LF, true, keywords, false);
+                         result, SVNUtil.EOL_LF, true, null_keywords, false);
             testout.write(contentsExpanded);
             testout.close();
             testout = null;
@@ -569,8 +573,7 @@ public class UtilTests extends SVNTests
             ByteArrayOutputStream result = new ByteArrayOutputStream();
             testout = SVNUtil.translateStream(
                          result, SVNUtil.EOL_LF, true, false,
-                         keywordsValue, 42, "http://a/b/c",
-                         "http://a", new Date(1), "X");
+                         keywordsValue, 0, "", "", new Date(1), "");
             testout.write(contentsExpanded);
             testout.close();
             testout = null;