You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2013/05/24 16:23:16 UTC

svn commit: r1486072 - in /subversion/trunk/subversion: libsvn_subr/subst.c tests/libsvn_subr/subst_translate-test.c

Author: stsp
Date: Fri May 24 14:23:16 2013
New Revision: 1486072

URL: http://svn.apache.org/r1486072
Log:
Fix expansion of custom keywords with values that contain '='.

* subversion/libsvn_subr/subst.c
  (build_keywords): Don't use svn_cstring_split() to find the '=' separator.
    It is not a suitable API for this purpose. Instead, scan for the first
    occurrence of '=' and split keyword name from custom format there.

* subversion/tests/libsvn_subr/subst_translate-test.c
  (test_svn_subst_build_keywords3): Expand to cover a custom keyword with '='.
   Also assert that a non-NULL expanded keyword value is returned to avoid
   crashing this test with a NULL-deref.

Reported by: Lorenz (lorenznl -@T- yahoo.com)

Modified:
    subversion/trunk/subversion/libsvn_subr/subst.c
    subversion/trunk/subversion/tests/libsvn_subr/subst_translate-test.c

Modified: subversion/trunk/subversion/libsvn_subr/subst.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/subst.c?rev=1486072&r1=1486071&r2=1486072&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/subst.c (original)
+++ subversion/trunk/subversion/libsvn_subr/subst.c Fri May 24 14:23:16 2013
@@ -298,14 +298,23 @@ build_keywords(apr_hash_t **kw,
   for (i = 0; i < keyword_tokens->nelts; ++i)
     {
       const char *keyword = APR_ARRAY_IDX(keyword_tokens, i, const char *);
-      apr_array_header_t *custom_keyword_tokens = NULL;
+      const char *custom_fmt = NULL;
 
       if (expand_custom_keywords)
-        custom_keyword_tokens = svn_cstring_split(keyword, "=",
-                                                  TRUE /* chop */, pool);
-      if (expand_custom_keywords && custom_keyword_tokens->nelts == 2)
         {
-          const char *custom_fmt;
+          char *sep;
+
+          /* Check if there is a custom keyword definition, started by '='. */
+          sep = strchr(keyword, '=');
+          if (sep)
+            {
+              *sep = '\0'; /* Split keyword's name from custom format. */
+              custom_fmt = sep + 1;
+            }
+        }
+
+      if (custom_fmt)
+        {
           svn_string_t *custom_val;
 
           /* Custom keywords must be allowed to match the name of an
@@ -313,9 +322,6 @@ build_keywords(apr_hash_t **kw,
            * in case new fixed keywords are added to Subversion which
            * happen to match a custom keyword defined somewhere.
            * There is only one global namespace for keyword names. */
-
-          keyword = APR_ARRAY_IDX(custom_keyword_tokens, 0, const char*);
-          custom_fmt = APR_ARRAY_IDX(custom_keyword_tokens, 1, const char*);
           custom_val = keyword_printf(custom_fmt, rev, url, repos_root_url,
                                       date, author, pool);
           svn_hash_sets(*kw, keyword, custom_val);

Modified: subversion/trunk/subversion/tests/libsvn_subr/subst_translate-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/subst_translate-test.c?rev=1486072&r1=1486071&r2=1486072&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/subst_translate-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/subst_translate-test.c Fri May 24 14:23:16 2013
@@ -269,6 +269,10 @@ test_svn_subst_build_keywords3(apr_pool_
        "trunk/foo.txt stsp foo.txt %",
        "1234", "http://svn.example.com/repos/trunk/foo.txt",
        "http://svn.example.com/repos", "stsp"},
+      {"FOO", "FOO=author%_=%_%a",
+       "author = stsp",
+       "1234", "http://svn.example.com/repos/trunk/foo.txt",
+       "http://svn.example.com/repos", "stsp"},
       {"MyKeyword", "MyKeyword=%r%_%u%_%_%a",
        "4567 http://svn.example.com/svn/branches/myfile  jrandom",
        "4567", "http://svn.example.com/svn/branches/myfile",
@@ -295,6 +299,7 @@ test_svn_subst_build_keywords3(apr_pool_
                                         t->rev, t->url, t->repos_root_url,
                                         0 /* date */, t->author, pool));
       expanded_keyword = svn_hash_gets(kw, t->keyword_name);
+      SVN_TEST_ASSERT(expanded_keyword != NULL);
       SVN_TEST_STRING_ASSERT(expanded_keyword->data, t->expanded_keyword);
     }