Skip to content

Commit 48960df

Browse files
author
Darragh Clarke
committed
8316734: URLEncoder should specify that replacement bytes will be used in case of coding error
Reviewed-by: dfuchs, alanb
1 parent 1594653 commit 48960df

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/java.base/share/classes/java/net/URLDecoder.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ private URLDecoder() {}
9898
* default charset. Instead, use the decode(String,String) method
9999
* to specify the encoding.
100100
* @return the newly decoded {@code String}
101+
* @throws IllegalArgumentException if the implementation encounters malformed
102+
* escape sequences
101103
*/
102104
@Deprecated
103105
public static String decode(String s) {
@@ -113,9 +115,6 @@ public static String decode(String s) {
113115
* except that it will {@linkplain Charset#forName look up the charset}
114116
* using the given encoding name.
115117
*
116-
* @implNote This implementation will throw an {@link java.lang.IllegalArgumentException}
117-
* when illegal strings are encountered.
118-
*
119118
* @param s the {@code String} to decode
120119
* @param enc The name of a supported
121120
* <a href="../lang/package-summary.html#charenc">character
@@ -124,6 +123,8 @@ public static String decode(String s) {
124123
* @throws UnsupportedEncodingException
125124
* If character encoding needs to be consulted, but
126125
* named character encoding is not supported
126+
* @throws IllegalArgumentException if the implementation encounters malformed
127+
* escape sequences
127128
* @see URLEncoder#encode(java.lang.String, java.lang.String)
128129
* @since 1.4
129130
*/
@@ -144,24 +145,23 @@ public static String decode(String s, String enc) throws UnsupportedEncodingExce
144145
* Decodes an {@code application/x-www-form-urlencoded} string using
145146
* a specific {@linkplain Charset Charset}.
146147
* The supplied charset is used to determine
147-
* what characters are represented by any consecutive sequences of the
148-
* form "<i>{@code %xy}</i>".
148+
* what characters are represented by any consecutive escape sequences of
149+
* the form "<i>{@code %xy}</i>". Erroneous bytes are replaced with the
150+
* supplied {@code Charset}'s {@linkplain java.nio.charset.CharsetDecoder##cae
151+
* replacement value}.
149152
* <p>
150153
* <em><strong>Note:</strong> The <a href=
151154
* "http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars">
152155
* World Wide Web Consortium Recommendation</a> states that
153156
* UTF-8 should be used. Not doing so may introduce
154157
* incompatibilities.</em>
155158
*
156-
* @implNote This implementation will throw an {@link java.lang.IllegalArgumentException}
157-
* when illegal strings are encountered.
158-
*
159159
* @param s the {@code String} to decode
160160
* @param charset the given charset
161161
* @return the newly decoded {@code String}
162162
* @throws NullPointerException if {@code s} or {@code charset} is {@code null}
163-
* @throws IllegalArgumentException if the implementation encounters illegal
164-
* characters
163+
* @throws IllegalArgumentException if the implementation encounters malformed
164+
* escape sequences
165165
*
166166
* @spec https://www.w3.org/TR/html4 HTML 4.01 Specification
167167
* @see URLEncoder#encode(java.lang.String, Charset)

src/java.base/share/classes/java/net/URLEncoder.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,15 @@ public static String encode(String s, String enc)
200200
* This method uses the supplied charset to obtain the bytes for unsafe
201201
* characters.
202202
* <p>
203-
* <em><strong>Note:</strong> The <a href=
203+
* If the input string is malformed, or if the input cannot be mapped
204+
* to a valid byte sequence in the given {@code Charset}, then the
205+
* erroneous input will be replaced with the {@code Charset}'s
206+
* {@linkplain CharsetEncoder##cae replacement values}.
207+
*
208+
* @apiNote The <a href=
204209
* "http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars">
205210
* World Wide Web Consortium Recommendation</a> states that
206-
* UTF-8 should be used. Not doing so may introduce incompatibilities.</em>
207-
*
211+
* UTF-8 should be used. Not doing so may introduce incompatibilities.
208212
* @param s {@code String} to be translated.
209213
* @param charset the given charset
210214
* @return the translated {@code String}.

0 commit comments

Comments
 (0)