mirror of
https://github.com/gbevin/urlencoder.git
synced 2025-04-25 07:17:11 -07:00
Prevent string allocation when not passing in any allowed characters.
This commit is contained in:
parent
262e9d6d29
commit
3e397a65d2
1 changed files with 15 additions and 1 deletions
|
@ -126,6 +126,20 @@ public final class UrlEncoder {
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms a provided <code>String</code> object into a new string,
|
||||||
|
* containing only valid URL characters in the UTF-8 encoding.
|
||||||
|
*
|
||||||
|
* @param source The string that has to be transformed into a valid URL
|
||||||
|
* string.
|
||||||
|
* @return The encoded <code>String</code> object.
|
||||||
|
* @see #decode(String)
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
public static String encode(String source) {
|
||||||
|
return encode(source, (String)null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms a provided <code>String</code> object into a new string,
|
* Transforms a provided <code>String</code> object into a new string,
|
||||||
* containing only valid URL characters in the UTF-8 encoding.
|
* containing only valid URL characters in the UTF-8 encoding.
|
||||||
|
@ -162,7 +176,7 @@ public final class UrlEncoder {
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while(i < source.length()) {
|
while(i < source.length()) {
|
||||||
ch = source.charAt(i);
|
ch = source.charAt(i);
|
||||||
if (isUnreservedUriChar(ch) || allow.indexOf(ch) != -1) {
|
if (isUnreservedUriChar(ch) || (allow != null && allow.indexOf(ch) != -1)) {
|
||||||
if (out != null) {
|
if (out != null) {
|
||||||
out.append(ch);
|
out.append(ch);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue