changeset 5834:b6d3fed1f4b5

8007315: HttpURLConnection.filterHeaderField method returns null where empty string is expected Reviewed-by: chegar
author coffeys
date Thu, 21 Mar 2013 12:37:00 +0000
parents 2e974e6ee037
children d07c9d4269fc
files src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java test/sun/net/www/protocol/http/HttpOnly.java
diffstat 2 files changed, 36 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java	Wed Mar 20 20:49:52 2013 +0400
+++ b/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java	Thu Mar 21 12:37:00 2013 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -2632,7 +2632,7 @@
                 multipleCookies = true;
             }
 
-            return retValue.length() == 0 ? null : retValue.toString();
+            return retValue.length() == 0 ? "" : retValue.toString();
         }
 
         return value;
--- a/test/sun/net/www/protocol/http/HttpOnly.java	Wed Mar 20 20:49:52 2013 +0400
+++ b/test/sun/net/www/protocol/http/HttpOnly.java	Thu Mar 21 12:37:00 2013 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -22,7 +22,7 @@
  */
 /**
  * @test
- * @bug 7095980
+ * @bug 7095980 8007315
  * @summary Ensure HttpURLConnection (and supporting APIs) don't expose
  *          HttpOnly cookies
  */
@@ -52,6 +52,8 @@
  * 4) check HttpOnly cookies received by server
  * 5) server reply with Set-Cookie containing HttpOnly cookie
  * 6) check HttpOnly cookies are not accessible from Http client
+ * 7) check that non-null (empty string) values are returned for
+      scenario where all values are stripped from original key values
  */
 
 public class HttpOnly {
@@ -177,6 +179,36 @@
                           " value " + val);
             }
         }
+
+        // TEST 7 : check that header keys containing empty key values don't return null
+        int i = 1;
+        String key = "";
+        String value = "";
+
+        while (true) {
+            key = uc.getHeaderFieldKey(i);
+            value = uc.getHeaderField(i++);
+            if (key == null && value == null)
+                break;
+
+            if (key != null)
+                check(value != null,
+                    "Encountered a null value for key value : " + key);
+        }
+
+        // TEST 7.5 similar test but use getHeaderFields
+        respHeaders = uc.getHeaderFields();
+        respEntries = respHeaders.entrySet();
+        for (Map.Entry<String,List<String>> entry : respEntries) {
+            String header = entry.getKey();
+            if (header != null) {
+                List<String> listValues = entry.getValue();
+                for (String value1 : listValues)
+                    check(value1 != null,
+                        "getHeaderFields returned null values for header:, "
+                        + header);
+            }
+        }
     }
 
     // HTTP Server