Skip to content

More work toward removing plusForSpace #961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/**
* Low-level JSON library implementation based on Jackson 2.
*
* <p>Implementation is thread-safe, and sub-classes must be thread-safe. For maximum efficiency,
* <p>Implementation is thread-safe. For maximum efficiency,
* applications should use a single globally-shared instance of the JSON factory.
*
* @since 1.11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public final class Atom {

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

static final class StopAtAtomEntry extends Xml.CustomizeParser {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
*/
public class GenericUrl extends GenericData {

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

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

/**
* Constructs from an encoded URL.
* Constructs a GenericUrl from a URL encoded string.
*
* <p>Any known query parameters with pre-defined fields as data keys will be parsed based on
* their data type. Any unrecognized query parameter will always be parsed as a string.
Expand All @@ -103,17 +102,17 @@ public GenericUrl() {}
* compliant with, at least, RFC 3986.
*
* @param encodedUrl encoded URL, including any existing query parameters that should be parsed
* @throws IllegalArgumentException if URL has a syntax error
* @throws IllegalArgumentException if the URL has a syntax error
*/
public GenericUrl(String encodedUrl) {
this(encodedUrl, false);
}

/**
* Constructs from an encoded URL.
* Constructs a GenericUrl from a string.
*
* <p>Any known query parameters with pre-defined fields as data keys are parsed based on their
* data type. Any unrecognized query parameter are always parsed as a string.
* <p>Any known query parameters with pre-defined fields as data keys will be parsed based on
* their data type. Any unrecognized query parameter will always be parsed as a string.
*
* <p>Any {@link MalformedURLException} is wrapped in an {@link IllegalArgumentException}.
*
Expand Down Expand Up @@ -216,7 +215,6 @@ private GenericUrl(

@Override
public int hashCode() {
// TODO(yanivi): optimize?
return build().hashCode();
}

Expand All @@ -229,7 +227,6 @@ public boolean equals(Object obj) {
return false;
}
GenericUrl other = (GenericUrl) obj;
// TODO(yanivi): optimize?
return build().equals(other.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class UrlEncodedParser implements ObjectParser {
public static void parse(String content, Object data) {
parse(content, data, true);
}

/**
* Parses the given URL-encoded content into the given data object of data key name/value pairs
* using {@link #parse(Reader, Object)}.
Expand All @@ -92,7 +92,7 @@ public static void parse(String content, Object data) {
* @param data data key name/value pairs
* @param decodeEnabled flag that specifies whether decoding should be enabled.
*/
public static void parse(String content, Object data, boolean decodeEnabled) {
public static void parse(String content, Object data, boolean decodeEnabled) {
if (content == null) {
return;
}
Expand All @@ -103,6 +103,7 @@ public static void parse(String content, Object data, boolean decodeEnabled) {
throw Throwables.propagate(exception);
}
}

/**
* Parses the given URL-encoded content into the given data object of data key name/value pairs,
* including support for repeating data key names.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2010 Google Inc.

*
* Licensed 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
Expand All @@ -19,27 +20,26 @@
import java.nio.charset.StandardCharsets;

/**
* Utility functions for dealing with {@code CharEscaper}s, and some commonly used {@code
* CharEscaper} instances.
* Utility functions for encoding and decoding URIs.
*
* @since 1.0
*/
public final class CharEscapers {

private static final Escaper URI_ESCAPER =
private static final Escaper APPLICATION_X_WWW_FORM_URLENCODED =
new PercentEscaper(PercentEscaper.SAFECHARS_URLENCODER, true);

private static final Escaper URI_PATH_ESCAPER =
new PercentEscaper(PercentEscaper.SAFEPATHCHARS_URLENCODER, false);
new PercentEscaper(PercentEscaper.SAFEPATHCHARS_URLENCODER);

private static final Escaper URI_RESERVED_ESCAPER =
new PercentEscaper(PercentEscaper.SAFE_PLUS_RESERVED_CHARS_URLENCODER, false);
new PercentEscaper(PercentEscaper.SAFE_PLUS_RESERVED_CHARS_URLENCODER);

private static final Escaper URI_USERINFO_ESCAPER =
new PercentEscaper(PercentEscaper.SAFEUSERINFOCHARS_URLENCODER, false);
new PercentEscaper(PercentEscaper.SAFEUSERINFOCHARS_URLENCODER);

private static final Escaper URI_QUERY_STRING_ESCAPER =
new PercentEscaper(PercentEscaper.SAFEQUERYSTRINGCHARS_URLENCODER, false);
new PercentEscaper(PercentEscaper.SAFEQUERYSTRINGCHARS_URLENCODER);

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

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

/**
* Decodes the path component of a URI. This must be done via a method that does not try to
* convert + into spaces(the behavior of {@link java.net.URLDecoder#decode(String, String)}). This
* Decodes the path component of a URI. This does not
* convert + into spaces (the behavior of {@link java.net.URLDecoder#decode(String, String)}). This
* method transforms URI encoded values into their decoded symbols.
*
* <p>i.e: {@code decodePath("%3Co%3E")} would return {@code "<o>"}
* <p>e.g. {@code decodePath("%3Co%3E")} returns {@code "<o>"}
*
* @param path the value to be decoded
* @return decoded version of {@code path}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ public void testDecodeUri_IllegalArgumentException() {
}

private void subtestDecodeUri_IllegalArgumentException(String input) {
boolean thrown = false;
try {
CharEscapers.decodeUriPath(input);
} catch (IllegalArgumentException e) {
thrown = true;
fail();
} catch (IllegalArgumentException expected) {
assertNotNull(expected.getMessage());
}
assertTrue(thrown);
}
}