You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-commits@axis.apache.org by ro...@apache.org on 2026/01/23 22:28:16 UTC

(axis-axis2-c-core) 01/05: Fix last POST parameter skipped when it has no value (AXIS2C-1532)

This is an automated email from the ASF dual-hosted git repository.

robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-c-core.git

commit 055eb8d5b44b290ed3cd00ea593d49a6282e66ed
Author: Robert Lazarski <ro...@gmail.com>
AuthorDate: Fri Jan 23 09:10:30 2026 -1000

    Fix last POST parameter skipped when it has no value (AXIS2C-1532)
    
    The bug was in axis2_http_transport_utils_get_request_params() which
    parsed URL query string parameters. After the parsing loop, there was
    a check that required the parameter value to be non-empty:
    
        if(tmp_name && AXIS2_ESC_NULL != *tmp2)
    
    This caused parameters with empty values to be skipped. For example,
    a query string like "param1=value1&param2=" would only include param1
    in the result hash, silently dropping param2.
    
    The fix removes the *tmp2 != '\0' check, allowing empty values to be
    stored. This matches the behavior described in the JIRA issue and is
    consistent with how other web frameworks handle empty query parameters.
    
    Added comprehensive test suite covering:
    - Normal parameters with values
    - Single parameter with empty value
    - Last parameter with empty value (the main bug)
    - Middle parameter with empty value
    - All parameters with empty values
    - No query string / empty query string
    - URL-encoded values
    
    Co-Authored-By: Claude Opus 4.5 <no...@anthropic.com>
---
 .../transport/http/util/http_transport_utils.c     |   6 +-
 test/core/transport/http/Makefile.am               |  35 ++-
 test/core/transport/http/test_axis2c_1532.cc       | 252 +++++++++++++++++++++
 3 files changed, 289 insertions(+), 4 deletions(-)

diff --git a/src/core/transport/http/util/http_transport_utils.c b/src/core/transport/http/util/http_transport_utils.c
index a92c6e903..595b0c297 100644
--- a/src/core/transport/http/util/http_transport_utils.c
+++ b/src/core/transport/http/util/http_transport_utils.c
@@ -1775,7 +1775,11 @@ axis2_http_transport_utils_get_request_params(
             tmp_value = NULL;
         }
     }
-    if(tmp_name && AXIS2_ESC_NULL != *tmp2)
+    /* AXIS2C-1532: Handle the last parameter after the loop ends.
+     * Previously this required *tmp2 != '\0', which skipped parameters with
+     * empty values (e.g., "param1=value1&param2=" would skip param2).
+     * Now we allow empty values - axutil_strdup of an empty string is valid. */
+    if(tmp_name)
     {
         if(!ret)
         {
diff --git a/test/core/transport/http/Makefile.am b/test/core/transport/http/Makefile.am
index 7239682eb..1b8035e26 100644
--- a/test/core/transport/http/Makefile.am
+++ b/test/core/transport/http/Makefile.am
@@ -27,9 +27,9 @@ TESTS =
 # HTTP/2 mode doesn't build the receiver/sender libraries that this test needs
 if GTEST_AVAILABLE
 if !WITH_NGHTTP2
-check_PROGRAMS += test_http_transport test_axis2c_1480
-noinst_PROGRAMS += test_http_transport test_axis2c_1480
-TESTS += test_http_transport test_axis2c_1480
+check_PROGRAMS += test_http_transport test_axis2c_1480 test_axis2c_1532
+noinst_PROGRAMS += test_http_transport test_axis2c_1480 test_axis2c_1532
+TESTS += test_http_transport test_axis2c_1480 test_axis2c_1532
 
 AM_CFLAGS = -g -pthread
 test_http_transport_SOURCES = test_http_transport.cc
@@ -78,6 +78,35 @@ test_axis2c_1480_CPPFLAGS = \
 			  -I ../../../../axiom/include \
 			  -I $(GTEST_DIR)/include
 
+# AXIS2C-1532: Empty parameter value tests
+test_axis2c_1532_SOURCES = test_axis2c_1532.cc
+
+test_axis2c_1532_LDADD = \
+							$(LDFLAGS) \
+							../../../../util/src/libaxutil.la \
+							../../../../axiom/src/om/libaxis2_axiom.la \
+							$(top_builddir)/neethi/src/libneethi.la \
+							../../../../axiom/src/parser/$(WRAPPER_DIR)/libaxis2_parser.la \
+							$(top_builddir)/src/core/engine/libaxis2_engine.la \
+							$(top_builddir)/src/core/transport/http/receiver/libaxis2_http_receiver.la \
+							$(top_builddir)/src/core/transport/http/sender/libaxis2_http_sender.la \
+							$(top_builddir)/src/core/transport/http/common/libaxis2_http_common.la \
+							$(top_builddir)/src/core/transport/http/util/libaxis2_http_util.la \
+							$(top_builddir)/$(GTEST)/libgtest.a \
+							$(top_builddir)/$(GTEST)/libgtest_main.a \
+							-lpthread
+
+# Ensure all shared libraries are linked even if not directly referenced by test code.
+# The test only calls axis2_http_transport_utils_get_request_params() which is in
+# libaxis2_http_util, but that library needs symbols from libaxis2_engine.
+test_axis2c_1532_LDFLAGS = -Wl,--no-as-needed
+
+test_axis2c_1532_CPPFLAGS = \
+			  -I$(top_builddir)/include \
+			  -I ../../../../util/include \
+			  -I ../../../../axiom/include \
+			  -I $(GTEST_DIR)/include
+
 # Add JSON support conditionally
 if AXIS2_JSON_ENABLED
 test_http_transport_LDADD += $(JSON_LIBS)
diff --git a/test/core/transport/http/test_axis2c_1532.cc b/test/core/transport/http/test_axis2c_1532.cc
new file mode 100644
index 000000000..a6c0018b1
--- /dev/null
+++ b/test/core/transport/http/test_axis2c_1532.cc
@@ -0,0 +1,252 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Test for AXIS2C-1532: Last POST parameter is skipped when it has no value
+ *
+ * This test verifies that URL query string parameters with empty values
+ * are correctly parsed and included in the parameter hash.
+ *
+ * The bug was that a query string like "param1=value1&param2=" would
+ * skip param2 because the code required the value to be non-empty.
+ */
+
+#include <gtest/gtest.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <axutil_env.h>
+#include <axutil_allocator.h>
+#include <axutil_error_default.h>
+#include <axutil_log_default.h>
+#include <axutil_hash.h>
+#include <axis2_http_transport_utils.h>
+
+class TestAxis2C1532 : public ::testing::Test
+{
+protected:
+    void SetUp() override
+    {
+        m_allocator = axutil_allocator_init(NULL);
+        ASSERT_NE(m_allocator, nullptr);
+
+        m_error = axutil_error_create(m_allocator);
+        ASSERT_NE(m_error, nullptr);
+
+        m_log = axutil_log_create(m_allocator, NULL, NULL);
+        ASSERT_NE(m_log, nullptr);
+
+        m_env = axutil_env_create_with_error_log(m_allocator, m_error, m_log);
+        ASSERT_NE(m_env, nullptr);
+    }
+
+    void TearDown() override
+    {
+        if (m_env)
+        {
+            axutil_env_free(m_env);
+            m_env = NULL;
+        }
+    }
+
+    /**
+     * Helper to get a value from the param hash and compare
+     */
+    void AssertParamValue(axutil_hash_t *params, const char *key, const char *expected_value)
+    {
+        ASSERT_NE(params, nullptr) << "params hash is NULL";
+        void *value = axutil_hash_get(params, key, AXIS2_HASH_KEY_STRING);
+        if (expected_value == NULL)
+        {
+            EXPECT_EQ(value, nullptr) << "Expected param '" << key << "' to be absent";
+        }
+        else
+        {
+            ASSERT_NE(value, nullptr) << "Param '" << key << "' not found in hash";
+            EXPECT_STREQ((char *)value, expected_value)
+                << "Param '" << key << "' has wrong value";
+        }
+    }
+
+    /**
+     * Helper to free param hash and its contents
+     */
+    void FreeParamHash(axutil_hash_t *params)
+    {
+        if (params)
+        {
+            axutil_hash_index_t *hi;
+            for (hi = axutil_hash_first(params, m_env); hi; hi = axutil_hash_next(m_env, hi))
+            {
+                const void *key;
+                void *value;
+                axutil_hash_this(hi, &key, NULL, &value);
+                if (value)
+                {
+                    AXIS2_FREE(m_env->allocator, value);
+                }
+            }
+            axutil_hash_free(params, m_env);
+        }
+    }
+
+    axutil_allocator_t *m_allocator = NULL;
+    axutil_env_t *m_env = NULL;
+    axutil_error_t *m_error = NULL;
+    axutil_log_t *m_log = NULL;
+};
+
+/**
+ * Test normal parameters with values - baseline test
+ */
+TEST_F(TestAxis2C1532, test_normal_params_with_values)
+{
+    char *uri = (char *)axutil_strdup(m_env,
+        "/service/method?param1=value1&param2=value2");
+
+    axutil_hash_t *params = axis2_http_transport_utils_get_request_params(m_env, uri);
+
+    ASSERT_NE(params, nullptr);
+    AssertParamValue(params, "param1", "value1");
+    AssertParamValue(params, "param2", "value2");
+
+    FreeParamHash(params);
+    AXIS2_FREE(m_env->allocator, uri);
+}
+
+/**
+ * Test single parameter with empty value
+ */
+TEST_F(TestAxis2C1532, test_single_param_empty_value)
+{
+    char *uri = (char *)axutil_strdup(m_env,
+        "/service/method?param1=");
+
+    axutil_hash_t *params = axis2_http_transport_utils_get_request_params(m_env, uri);
+
+    ASSERT_NE(params, nullptr) << "Should return hash even for empty value";
+    AssertParamValue(params, "param1", "");
+
+    FreeParamHash(params);
+    AXIS2_FREE(m_env->allocator, uri);
+}
+
+/**
+ * AXIS2C-1532: Last parameter with empty value should NOT be skipped
+ * This is the main regression test for the bug.
+ */
+TEST_F(TestAxis2C1532, test_last_param_empty_value)
+{
+    char *uri = (char *)axutil_strdup(m_env,
+        "/service/method?param1=value1&param2=");
+
+    axutil_hash_t *params = axis2_http_transport_utils_get_request_params(m_env, uri);
+
+    ASSERT_NE(params, nullptr);
+    AssertParamValue(params, "param1", "value1");
+    /* AXIS2C-1532: This used to fail - param2 was skipped */
+    AssertParamValue(params, "param2", "");
+
+    FreeParamHash(params);
+    AXIS2_FREE(m_env->allocator, uri);
+}
+
+/**
+ * Test multiple parameters where middle one has empty value
+ */
+TEST_F(TestAxis2C1532, test_middle_param_empty_value)
+{
+    char *uri = (char *)axutil_strdup(m_env,
+        "/service/method?param1=value1&param2=&param3=value3");
+
+    axutil_hash_t *params = axis2_http_transport_utils_get_request_params(m_env, uri);
+
+    ASSERT_NE(params, nullptr);
+    AssertParamValue(params, "param1", "value1");
+    AssertParamValue(params, "param2", "");
+    AssertParamValue(params, "param3", "value3");
+
+    FreeParamHash(params);
+    AXIS2_FREE(m_env->allocator, uri);
+}
+
+/**
+ * Test all parameters with empty values
+ */
+TEST_F(TestAxis2C1532, test_all_params_empty_values)
+{
+    char *uri = (char *)axutil_strdup(m_env,
+        "/service/method?param1=&param2=&param3=");
+
+    axutil_hash_t *params = axis2_http_transport_utils_get_request_params(m_env, uri);
+
+    ASSERT_NE(params, nullptr);
+    AssertParamValue(params, "param1", "");
+    AssertParamValue(params, "param2", "");
+    AssertParamValue(params, "param3", "");
+
+    FreeParamHash(params);
+    AXIS2_FREE(m_env->allocator, uri);
+}
+
+/**
+ * Test no query string - should return NULL
+ */
+TEST_F(TestAxis2C1532, test_no_query_string)
+{
+    char *uri = (char *)axutil_strdup(m_env,
+        "/service/method");
+
+    axutil_hash_t *params = axis2_http_transport_utils_get_request_params(m_env, uri);
+
+    EXPECT_EQ(params, nullptr) << "Should return NULL when no query string";
+
+    AXIS2_FREE(m_env->allocator, uri);
+}
+
+/**
+ * Test empty query string (just ?) - should return NULL
+ */
+TEST_F(TestAxis2C1532, test_empty_query_string)
+{
+    char *uri = (char *)axutil_strdup(m_env,
+        "/service/method?");
+
+    axutil_hash_t *params = axis2_http_transport_utils_get_request_params(m_env, uri);
+
+    EXPECT_EQ(params, nullptr) << "Should return NULL for empty query string";
+
+    AXIS2_FREE(m_env->allocator, uri);
+}
+
+/**
+ * Test URL-encoded values
+ */
+TEST_F(TestAxis2C1532, test_url_encoded_values)
+{
+    char *uri = (char *)axutil_strdup(m_env,
+        "/service/method?param1=hello%20world&param2=foo%26bar");
+
+    axutil_hash_t *params = axis2_http_transport_utils_get_request_params(m_env, uri);
+
+    ASSERT_NE(params, nullptr);
+    AssertParamValue(params, "param1", "hello world");
+    AssertParamValue(params, "param2", "foo&bar");
+
+    FreeParamHash(params);
+    AXIS2_FREE(m_env->allocator, uri);
+}