Skip to content

Commit fe1a386

Browse files
author
Mathieu Hubbard
committed
Merge upstream/master to master
2 parents fd0a399 + cdf3cf7 commit fe1a386

File tree

14 files changed

+1150
-313
lines changed

14 files changed

+1150
-313
lines changed

CDL.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ of this software and associated documentation files (the "Software"), to deal
2222
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2323
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2424
SOFTWARE.
25-
*/
25+
*/
2626

2727
/**
2828
* This provides static methods to convert comma delimited text into a
@@ -70,9 +70,12 @@ private static String getValue(JSONTokener x) throws JSONException {
7070
c = x.next();
7171
if (c == q) {
7272
//Handle escaped double-quote
73-
if(x.next() != '\"')
74-
{
75-
x.back();
73+
char nextC = x.next();
74+
if(nextC != '\"') {
75+
// if our quote was the end of the file, don't step
76+
if(nextC > 0) {
77+
x.back();
78+
}
7679
break;
7780
}
7881
}

CookieList.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.json;
22

3+
import java.util.Map.Entry;
4+
35
/*
46
Copyright (c) 2002 JSON.org
57
@@ -24,8 +26,6 @@ of this software and associated documentation files (the "Software"), to deal
2426
SOFTWARE.
2527
*/
2628

27-
import java.util.Iterator;
28-
2929
/**
3030
* Convert a web browser cookie list string to a JSONObject and back.
3131
* @author JSON.org
@@ -39,7 +39,7 @@ public class CookieList {
3939
* The pairs are separated by ';'. The names and the values
4040
* will be unescaped, possibly converting '+' and '%' sequences.
4141
*
42-
* To add a cookie to a cooklist,
42+
* To add a cookie to a cookie list,
4343
* cookielistJSONObject.put(cookieJSONObject.getString("name"),
4444
* cookieJSONObject.getString("value"));
4545
* @param string A cookie list string
@@ -69,18 +69,17 @@ public static JSONObject toJSONObject(String string) throws JSONException {
6969
*/
7070
public static String toString(JSONObject jo) throws JSONException {
7171
boolean b = false;
72-
Iterator<String> keys = jo.keys();
73-
String string;
7472
StringBuilder sb = new StringBuilder();
75-
while (keys.hasNext()) {
76-
string = keys.next();
77-
if (!jo.isNull(string)) {
73+
for (final Entry<String,?> entry : jo.entrySet()) {
74+
final String key = entry.getKey();
75+
final Object value = entry.getValue();
76+
if (!JSONObject.NULL.equals(value)) {
7877
if (b) {
7978
sb.append(';');
8079
}
81-
sb.append(Cookie.escape(string));
80+
sb.append(Cookie.escape(key));
8281
sb.append("=");
83-
sb.append(Cookie.escape(jo.getString(string)));
82+
sb.append(Cookie.escape(value.toString()));
8483
b = true;
8584
}
8685
}

HTTP.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ of this software and associated documentation files (the "Software"), to deal
2424
SOFTWARE.
2525
*/
2626

27-
import java.util.Iterator;
27+
import java.util.Locale;
28+
import java.util.Map.Entry;
2829

2930
/**
3031
* Convert an HTTP header to a JSONObject and back.
@@ -74,7 +75,7 @@ public static JSONObject toJSONObject(String string) throws JSONException {
7475
String token;
7576

7677
token = x.nextToken();
77-
if (token.toUpperCase().startsWith("HTTP")) {
78+
if (token.toUpperCase(Locale.ROOT).startsWith("HTTP")) {
7879

7980
// Response
8081

@@ -125,8 +126,6 @@ public static JSONObject toJSONObject(String string) throws JSONException {
125126
* information.
126127
*/
127128
public static String toString(JSONObject jo) throws JSONException {
128-
Iterator<String> keys = jo.keys();
129-
String string;
130129
StringBuilder sb = new StringBuilder();
131130
if (jo.has("Status-Code") && jo.has("Reason-Phrase")) {
132131
sb.append(jo.getString("HTTP-Version"));
@@ -146,14 +145,14 @@ public static String toString(JSONObject jo) throws JSONException {
146145
throw new JSONException("Not enough material for an HTTP header.");
147146
}
148147
sb.append(CRLF);
149-
while (keys.hasNext()) {
150-
string = keys.next();
151-
if (!"HTTP-Version".equals(string) && !"Status-Code".equals(string) &&
152-
!"Reason-Phrase".equals(string) && !"Method".equals(string) &&
153-
!"Request-URI".equals(string) && !jo.isNull(string)) {
154-
sb.append(string);
148+
for (final Entry<String,?> entry : jo.entrySet()) {
149+
final String key = entry.getKey();
150+
if (!"HTTP-Version".equals(key) && !"Status-Code".equals(key) &&
151+
!"Reason-Phrase".equals(key) && !"Method".equals(key) &&
152+
!"Request-URI".equals(key) && !JSONObject.NULL.equals(entry.getValue())) {
153+
sb.append(key);
155154
sb.append(": ");
156-
sb.append(jo.getString(string));
155+
sb.append(jo.optString(key));
157156
sb.append(CRLF);
158157
}
159158
}

0 commit comments

Comments
 (0)