Skip to content

Commit 67d5eb1

Browse files
authored
More work toward removing plusForSpace (#961)
* more standard exception test * replace deprecated methods * update Javadoc * update Javadoc * rename variable for clarity * replace deprecated methods * remove obsolete javadoc * restore some comments * replace deprecated method * unused import * class is final
1 parent 879d81a commit 67d5eb1

File tree

7 files changed

+29
-33
lines changed

7 files changed

+29
-33
lines changed

google-http-client-jackson2/src/main/java/com/google/api/client/json/jackson2/JacksonFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/**
3030
* Low-level JSON library implementation based on Jackson 2.
3131
*
32-
* <p>Implementation is thread-safe, and sub-classes must be thread-safe. For maximum efficiency,
32+
* <p>Implementation is thread-safe. For maximum efficiency,
3333
* applications should use a single globally-shared instance of the JSON factory.
3434
*
3535
* @since 1.11

google-http-client-xml/src/main/java/com/google/api/client/xml/atom/Atom.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public final class Atom {
4949

5050
/** Escaper for the {@code Slug} header. */
5151
private static final PercentEscaper SLUG_ESCAPER =
52-
new PercentEscaper(" !\"#$&'()*+,-./:;<=>?@[\\]^_`{|}~", false);
52+
new PercentEscaper(" !\"#$&'()*+,-./:;<=>?@[\\]^_`{|}~");
5353

5454
static final class StopAtAtomEntry extends Xml.CustomizeParser {
5555

google-http-client/src/main/java/com/google/api/client/http/GenericUrl.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@
5252
*/
5353
public class GenericUrl extends GenericData {
5454

55-
private static final Escaper URI_FRAGMENT_ESCAPER =
56-
new PercentEscaper("=&-_.!~*'()@:$,;/?:", false);
55+
private static final Escaper URI_FRAGMENT_ESCAPER = new PercentEscaper("=&-_.!~*'()@:$,;/?:");
5756

5857
/** Scheme (lowercase), for example {@code "https"}. */
5958
private String scheme;
@@ -90,7 +89,7 @@ public class GenericUrl extends GenericData {
9089
public GenericUrl() {}
9190

9291
/**
93-
* Constructs from an encoded URL.
92+
* Constructs a GenericUrl from a URL encoded string.
9493
*
9594
* <p>Any known query parameters with pre-defined fields as data keys will be parsed based on
9695
* their data type. Any unrecognized query parameter will always be parsed as a string.
@@ -103,17 +102,17 @@ public GenericUrl() {}
103102
* compliant with, at least, RFC 3986.
104103
*
105104
* @param encodedUrl encoded URL, including any existing query parameters that should be parsed
106-
* @throws IllegalArgumentException if URL has a syntax error
105+
* @throws IllegalArgumentException if the URL has a syntax error
107106
*/
108107
public GenericUrl(String encodedUrl) {
109108
this(encodedUrl, false);
110109
}
111110

112111
/**
113-
* Constructs from an encoded URL.
112+
* Constructs a GenericUrl from a string.
114113
*
115-
* <p>Any known query parameters with pre-defined fields as data keys are parsed based on their
116-
* data type. Any unrecognized query parameter are always parsed as a string.
114+
* <p>Any known query parameters with pre-defined fields as data keys will be parsed based on
115+
* their data type. Any unrecognized query parameter will always be parsed as a string.
117116
*
118117
* <p>Any {@link MalformedURLException} is wrapped in an {@link IllegalArgumentException}.
119118
*
@@ -216,7 +215,6 @@ private GenericUrl(
216215

217216
@Override
218217
public int hashCode() {
219-
// TODO(yanivi): optimize?
220218
return build().hashCode();
221219
}
222220

@@ -229,7 +227,6 @@ public boolean equals(Object obj) {
229227
return false;
230228
}
231229
GenericUrl other = (GenericUrl) obj;
232-
// TODO(yanivi): optimize?
233230
return build().equals(other.build());
234231
}
235232

google-http-client/src/main/java/com/google/api/client/http/UrlEncodedParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public class UrlEncodedParser implements ObjectParser {
8383
public static void parse(String content, Object data) {
8484
parse(content, data, true);
8585
}
86-
86+
8787
/**
8888
* Parses the given URL-encoded content into the given data object of data key name/value pairs
8989
* using {@link #parse(Reader, Object)}.
@@ -92,7 +92,7 @@ public static void parse(String content, Object data) {
9292
* @param data data key name/value pairs
9393
* @param decodeEnabled flag that specifies whether decoding should be enabled.
9494
*/
95-
public static void parse(String content, Object data, boolean decodeEnabled) {
95+
public static void parse(String content, Object data, boolean decodeEnabled) {
9696
if (content == null) {
9797
return;
9898
}
@@ -103,6 +103,7 @@ public static void parse(String content, Object data, boolean decodeEnabled) {
103103
throw Throwables.propagate(exception);
104104
}
105105
}
106+
106107
/**
107108
* Parses the given URL-encoded content into the given data object of data key name/value pairs,
108109
* including support for repeating data key names.

google-http-client/src/main/java/com/google/api/client/util/escape/CharEscapers.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2010 Google Inc.
3+
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
56
* in compliance with the License. You may obtain a copy of the License at
@@ -19,27 +20,26 @@
1920
import java.nio.charset.StandardCharsets;
2021

2122
/**
22-
* Utility functions for dealing with {@code CharEscaper}s, and some commonly used {@code
23-
* CharEscaper} instances.
23+
* Utility functions for encoding and decoding URIs.
2424
*
2525
* @since 1.0
2626
*/
2727
public final class CharEscapers {
2828

29-
private static final Escaper URI_ESCAPER =
29+
private static final Escaper APPLICATION_X_WWW_FORM_URLENCODED =
3030
new PercentEscaper(PercentEscaper.SAFECHARS_URLENCODER, true);
3131

3232
private static final Escaper URI_PATH_ESCAPER =
33-
new PercentEscaper(PercentEscaper.SAFEPATHCHARS_URLENCODER, false);
33+
new PercentEscaper(PercentEscaper.SAFEPATHCHARS_URLENCODER);
3434

3535
private static final Escaper URI_RESERVED_ESCAPER =
36-
new PercentEscaper(PercentEscaper.SAFE_PLUS_RESERVED_CHARS_URLENCODER, false);
36+
new PercentEscaper(PercentEscaper.SAFE_PLUS_RESERVED_CHARS_URLENCODER);
3737

3838
private static final Escaper URI_USERINFO_ESCAPER =
39-
new PercentEscaper(PercentEscaper.SAFEUSERINFOCHARS_URLENCODER, false);
39+
new PercentEscaper(PercentEscaper.SAFEUSERINFOCHARS_URLENCODER);
4040

4141
private static final Escaper URI_QUERY_STRING_ESCAPER =
42-
new PercentEscaper(PercentEscaper.SAFEQUERYSTRINGCHARS_URLENCODER, false);
42+
new PercentEscaper(PercentEscaper.SAFEQUERYSTRINGCHARS_URLENCODER);
4343

4444
/**
4545
* Escapes the string value so it can be safely included in URIs. For details on escaping URIs,
@@ -69,18 +69,18 @@ public final class CharEscapers {
6969
* </ul>
7070
*/
7171
public static String escapeUri(String value) {
72-
return URI_ESCAPER.escape(value);
72+
return APPLICATION_X_WWW_FORM_URLENCODED.escape(value);
7373
}
7474

7575
/**
76-
* Percent-decodes a US-ASCII string into a Unicode string. UTF-8 encoding is used to determine
76+
* Decodes application/x-www-form-urlencoded strings. The UTF-8 character set determines
7777
* what characters are represented by any consecutive sequences of the form "%<i>XX</i>".
7878
*
79-
* <p>This replaces each occurrence of '+' with a space, ' '. So this method should not be used
80-
* for non application/x-www-form-urlencoded strings such as host and path.
79+
* <p>This replaces each occurrence of '+' with a space, ' '. This method should not be used
80+
* for non-application/x-www-form-urlencoded strings such as host and path.
8181
*
8282
* @param uri a percent-encoded US-ASCII string
83-
* @return a Unicode string
83+
* @return a string without any percent escapes or plus signs
8484
*/
8585
public static String decodeUri(String uri) {
8686
try {
@@ -92,11 +92,11 @@ public static String decodeUri(String uri) {
9292
}
9393

9494
/**
95-
* Decodes the path component of a URI. This must be done via a method that does not try to
96-
* convert + into spaces(the behavior of {@link java.net.URLDecoder#decode(String, String)}). This
95+
* Decodes the path component of a URI. This does not
96+
* convert + into spaces (the behavior of {@link java.net.URLDecoder#decode(String, String)}). This
9797
* method transforms URI encoded values into their decoded symbols.
9898
*
99-
* <p>i.e: {@code decodePath("%3Co%3E")} would return {@code "<o>"}
99+
* <p>e.g. {@code decodePath("%3Co%3E")} returns {@code "<o>"}
100100
*
101101
* @param path the value to be decoded
102102
* @return decoded version of {@code path}

google-http-client/src/test/java/com/google/api/client/http/ConsumingInputStreamTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import java.io.IOException;
2222
import java.io.InputStream;
23-
import java.nio.charset.Charset;
2423
import java.nio.charset.StandardCharsets;
2524
import org.junit.Test;
2625

google-http-client/src/test/java/com/google/api/client/util/escape/CharEscapersTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ public void testDecodeUri_IllegalArgumentException() {
3838
}
3939

4040
private void subtestDecodeUri_IllegalArgumentException(String input) {
41-
boolean thrown = false;
4241
try {
4342
CharEscapers.decodeUriPath(input);
44-
} catch (IllegalArgumentException e) {
45-
thrown = true;
43+
fail();
44+
} catch (IllegalArgumentException expected) {
45+
assertNotNull(expected.getMessage());
4646
}
47-
assertTrue(thrown);
4847
}
4948
}

0 commit comments

Comments
 (0)