Blame SOURCES/0002-Replace-bundled-gdata-java-client-classes-with-commo.patch

409d12
From f06ff492f18d7c9cdf861a79293279e5ed55823f Mon Sep 17 00:00:00 2001
409d12
From: Michal Srb <msrb@redhat.com>
409d12
Date: Fri, 26 Apr 2013 07:32:04 +0200
409d12
Subject: [PATCH 2/2] Replace bundled gdata-java-client classes with
409d12
 commons-codec
409d12
409d12
---
409d12
 .../com/google/gdata/util/common/base/Escaper.java |  97 ----
409d12
 .../gdata/util/common/base/PercentEscaper.java     | 281 ------------
409d12
 .../gdata/util/common/base/UnicodeEscaper.java     | 506 ---------------------
409d12
 .../java/org/yaml/snakeyaml/util/UriEncoder.java   |  37 +-
409d12
 4 files changed, 29 insertions(+), 892 deletions(-)
409d12
 delete mode 100644 src/main/java/org/yaml/snakeyaml/external/com/google/gdata/util/common/base/Escaper.java
409d12
 delete mode 100644 src/main/java/org/yaml/snakeyaml/external/com/google/gdata/util/common/base/PercentEscaper.java
409d12
 delete mode 100644 src/main/java/org/yaml/snakeyaml/external/com/google/gdata/util/common/base/UnicodeEscaper.java
409d12
409d12
diff --git a/src/main/java/org/yaml/snakeyaml/external/com/google/gdata/util/common/base/Escaper.java b/src/main/java/org/yaml/snakeyaml/external/com/google/gdata/util/common/base/Escaper.java
409d12
deleted file mode 100644
409d12
index c26e3cb..0000000
409d12
--- a/src/main/java/org/yaml/snakeyaml/external/com/google/gdata/util/common/base/Escaper.java
409d12
+++ /dev/null
409d12
@@ -1,97 +0,0 @@
409d12
-/* Copyright (c) 2008 Google Inc.
409d12
- *
409d12
- * Licensed under the Apache License, Version 2.0 (the "License");
409d12
- * you may not use this file except in compliance with the License.
409d12
- * You may obtain a copy of the License at
409d12
- *
409d12
- *     http://www.apache.org/licenses/LICENSE-2.0
409d12
- *
409d12
- * Unless required by applicable law or agreed to in writing, software
409d12
- * distributed under the License is distributed on an "AS IS" BASIS,
409d12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
409d12
- * See the License for the specific language governing permissions and
409d12
- * limitations under the License.
409d12
- */
409d12
-
409d12
-package org.yaml.snakeyaml.external.com.google.gdata.util.common.base;
409d12
-
409d12
-/**
409d12
- * An object that converts literal text into a format safe for inclusion in a
409d12
- * particular context (such as an XML document). Typically (but not always), the
409d12
- * inverse process of "unescaping" the text is performed automatically by the
409d12
- * relevant parser.
409d12
- * 
409d12
- * 

409d12
- * For example, an XML escaper would convert the literal string
409d12
- * {@code "Foo<Bar>"} into {@code "Foo<Bar>"} to prevent {@code "<Bar>"}
409d12
- * from being confused with an XML tag. When the resulting XML document is
409d12
- * parsed, the parser API will return this text as the original literal string
409d12
- * {@code "Foo<Bar>"}.
409d12
- * 
409d12
- * 

409d12
- * An {@code Escaper} instance is required to be stateless, and safe when used
409d12
- * concurrently by multiple threads.
409d12
- * 
409d12
- * 

409d12
- * Several popular escapers are defined as constants in the class
409d12
- * {@link CharEscapers}. To create your own escapers, use
409d12
- * {@link CharEscaperBuilder}, or extend {@link CharEscaper} or
409d12
- * {@code UnicodeEscaper}.
409d12
- * 
409d12
- * 
409d12
- */
409d12
-public interface Escaper {
409d12
-    /**
409d12
-     * Returns the escaped form of a given literal string.
409d12
-     * 
409d12
-     * 

409d12
-     * Note that this method may treat input characters differently depending on
409d12
-     * the specific escaper implementation.
409d12
-     * 
    409d12
    -     * 
  • {@link UnicodeEscaper} handles
  • 409d12
    -     * href="http://en.wikipedia.org/wiki/UTF-16">UTF-16 correctly,
    409d12
    -     * including surrogate character pairs. If the input is badly formed the
    409d12
    -     * escaper should throw {@link IllegalArgumentException}.
    409d12
    -     * 
  • {@link CharEscaper} handles Java characters independently and does
  • 409d12
    -     * not verify the input for well formed characters. A CharEscaper should not
    409d12
    -     * be used in situations where input is not guaranteed to be restricted to
    409d12
    -     * the Basic Multilingual Plane (BMP).
    409d12
    -     * 
    409d12
    -     * 
    409d12
    -     * @param string
    409d12
    -     *            the literal string to be escaped
    409d12
    -     * @return the escaped form of {@code string}
    409d12
    -     * @throws NullPointerException
    409d12
    -     *             if {@code string} is null
    409d12
    -     * @throws IllegalArgumentException
    409d12
    -     *             if {@code string} contains badly formed UTF-16 or cannot be
    409d12
    -     *             escaped for any other reason
    409d12
    -     */
    409d12
    -    public String escape(String string);
    409d12
    -
    409d12
    -    /**
    409d12
    -     * Returns an {@code Appendable} instance which automatically escapes all
    409d12
    -     * text appended to it before passing the resulting text to an underlying
    409d12
    -     * {@code Appendable}.
    409d12
    -     * 
    409d12
    -     * 

    409d12
    -     * Note that this method may treat input characters differently depending on
    409d12
    -     * the specific escaper implementation.
    409d12
    -     * 
      409d12
      -     * 
    • {@link UnicodeEscaper} handles
    • 409d12
      -     * href="http://en.wikipedia.org/wiki/UTF-16">UTF-16 correctly,
      409d12
      -     * including surrogate character pairs. If the input is badly formed the
      409d12
      -     * escaper should throw {@link IllegalArgumentException}.
      409d12
      -     * 
    • {@link CharEscaper} handles Java characters independently and does
    • 409d12
      -     * not verify the input for well formed characters. A CharEscaper should not
      409d12
      -     * be used in situations where input is not guaranteed to be restricted to
      409d12
      -     * the Basic Multilingual Plane (BMP).
      409d12
      -     * 
      409d12
      -     * 
      409d12
      -     * @param out
      409d12
      -     *            the underlying {@code Appendable} to append escaped output to
      409d12
      -     * @return an {@code Appendable} which passes text to {@code out} after
      409d12
      -     *         escaping it.
      409d12
      -     */
      409d12
      -    public Appendable escape(Appendable out);
      409d12
      -}
      409d12
      diff --git a/src/main/java/org/yaml/snakeyaml/external/com/google/gdata/util/common/base/PercentEscaper.java b/src/main/java/org/yaml/snakeyaml/external/com/google/gdata/util/common/base/PercentEscaper.java
      409d12
      deleted file mode 100644
      409d12
      index 5e2f902..0000000
      409d12
      --- a/src/main/java/org/yaml/snakeyaml/external/com/google/gdata/util/common/base/PercentEscaper.java
      409d12
      +++ /dev/null
      409d12
      @@ -1,281 +0,0 @@
      409d12
      -/* Copyright (c) 2008 Google Inc.
      409d12
      - *
      409d12
      - * Licensed under the Apache License, Version 2.0 (the "License");
      409d12
      - * you may not use this file except in compliance with the License.
      409d12
      - * You may obtain a copy of the License at
      409d12
      - *
      409d12
      - *     http://www.apache.org/licenses/LICENSE-2.0
      409d12
      - *
      409d12
      - * Unless required by applicable law or agreed to in writing, software
      409d12
      - * distributed under the License is distributed on an "AS IS" BASIS,
      409d12
      - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      409d12
      - * See the License for the specific language governing permissions and
      409d12
      - * limitations under the License.
      409d12
      - */
      409d12
      -
      409d12
      -package org.yaml.snakeyaml.external.com.google.gdata.util.common.base;
      409d12
      -
      409d12
      -/**
      409d12
      - * A {@code UnicodeEscaper} that escapes some set of Java characters using the
      409d12
      - * URI percent encoding scheme. The set of safe characters (those which remain
      409d12
      - * unescaped) can be specified on construction.
      409d12
      - * 
      409d12
      - * 

      409d12
      - * For details on escaping URIs for use in web pages, see section 2.4 of 
      409d12
      - * href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986.
      409d12
      - * 
      409d12
      - * 

      409d12
      - * In most cases this class should not need to be used directly. If you have no
      409d12
      - * special requirements for escaping your URIs, you should use either
      409d12
      - * {@link CharEscapers#uriEscaper()} or {@link CharEscapers#uriEscaper(boolean)}.
      409d12
      - * 
      409d12
      - * 

      409d12
      - * When encoding a String, the following rules apply:
      409d12
      - * 
        409d12
        - * 
      • The alphanumeric characters "a" through "z", "A" through "Z" and "0"
      • 409d12
        - * through "9" remain the same.
        409d12
        - * 
      • Any additionally specified safe characters remain the same.
      • 409d12
        - * 
      • If {@code plusForSpace} was specified, the space character " " is
      • 409d12
        - * converted into a plus sign "+".
        409d12
        - * 
      • All other characters are converted into one or more bytes using UTF-8
      • 409d12
        - * encoding and each byte is then represented by the 3-character string "%XY",
        409d12
        - * where "XY" is the two-digit, uppercase, hexadecimal representation of the
        409d12
        - * byte value.
        409d12
        - * 
        409d12
        - * 
        409d12
        - * 

        409d12
        - * RFC 2396 specifies the set of unreserved characters as "-", "_", ".", "!",
        409d12
        - * "~", "*", "'", "(" and ")". It goes on to state:
        409d12
        - * 
        409d12
        - * 

        409d12
        - * Unreserved characters can be escaped without changing the semantics of the
        409d12
        - * URI, but this should not be done unless the URI is being used in a context
        409d12
        - * that does not allow the unescaped character to appear.
        409d12
        - * 
        409d12
        - * 

        409d12
        - * For performance reasons the only currently supported character encoding of
        409d12
        - * this class is UTF-8.
        409d12
        - * 
        409d12
        - * 

        409d12
        - * Note: This escaper produces uppercase hexidecimal sequences. From 
        409d12
        - * href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986:
        409d12
        - * "URI producers and normalizers should use uppercase hexadecimal digits for
        409d12
        - * all percent-encodings."
        409d12
        - * 
        409d12
        - * 
        409d12
        - */
        409d12
        -public class PercentEscaper extends UnicodeEscaper {
        409d12
        -    /**
        409d12
        -     * A string of safe characters that mimics the behavior of
        409d12
        -     * {@link java.net.URLEncoder}.
        409d12
        -     * 
        409d12
        -     */
        409d12
        -    public static final String SAFECHARS_URLENCODER = "-_.*";
        409d12
        -
        409d12
        -    /**
        409d12
        -     * A string of characters that do not need to be encoded when used in URI
        409d12
        -     * path segments, as specified in RFC 3986. Note that some of these
        409d12
        -     * characters do need to be escaped when used in other parts of the URI.
        409d12
        -     */
        409d12
        -    public static final String SAFEPATHCHARS_URLENCODER = "-_.!~*'()@:$&,;=";
        409d12
        -
        409d12
        -    /**
        409d12
        -     * A string of characters that do not need to be encoded when used in URI
        409d12
        -     * query strings, as specified in RFC 3986. Note that some of these
        409d12
        -     * characters do need to be escaped when used in other parts of the URI.
        409d12
        -     */
        409d12
        -    public static final String SAFEQUERYSTRINGCHARS_URLENCODER = "-_.!~*'()@:$,;/?:";
        409d12
        -
        409d12
        -    // In some uri escapers spaces are escaped to '+'
        409d12
        -    private static final char[] URI_ESCAPED_SPACE = { '+' };
        409d12
        -
        409d12
        -    private static final char[] UPPER_HEX_DIGITS = "0123456789ABCDEF".toCharArray();
        409d12
        -
        409d12
        -    /**
        409d12
        -     * If true we should convert space to the {@code +} character.
        409d12
        -     */
        409d12
        -    private final boolean plusForSpace;
        409d12
        -
        409d12
        -    /**
        409d12
        -     * An array of flags where for any {@code char c} if {@code safeOctets[c]}
        409d12
        -     * is true then {@code c} should remain unmodified in the output. If
        409d12
        -     * {@code c > safeOctets.length} then it should be escaped.
        409d12
        -     */
        409d12
        -    private final boolean[] safeOctets;
        409d12
        -
        409d12
        -    /**
        409d12
        -     * Constructs a URI escaper with the specified safe characters and optional
        409d12
        -     * handling of the space character.
        409d12
        -     * 
        409d12
        -     * @param safeChars
        409d12
        -     *            a non null string specifying additional safe characters for
        409d12
        -     *            this escaper (the ranges 0..9, a..z and A..Z are always safe
        409d12
        -     *            and should not be specified here)
        409d12
        -     * @param plusForSpace
        409d12
        -     *            true if ASCII space should be escaped to {@code +} rather than
        409d12
        -     *            {@code %20}
        409d12
        -     * @throws IllegalArgumentException
        409d12
        -     *             if any of the parameters were invalid
        409d12
        -     */
        409d12
        -    public PercentEscaper(String safeChars, boolean plusForSpace) {
        409d12
        -        // Avoid any misunderstandings about the behavior of this escaper
        409d12
        -        if (safeChars.matches(".*[0-9A-Za-z].*")) {
        409d12
        -            throw new IllegalArgumentException(
        409d12
        -                    "Alphanumeric characters are always 'safe' and should not be "
        409d12
        -                            + "explicitly specified");
        409d12
        -        }
        409d12
        -        // Avoid ambiguous parameters. Safe characters are never modified so if
        409d12
        -        // space is a safe character then setting plusForSpace is meaningless.
        409d12
        -        if (plusForSpace && safeChars.contains(" ")) {
        409d12
        -            throw new IllegalArgumentException(
        409d12
        -                    "plusForSpace cannot be specified when space is a 'safe' character");
        409d12
        -        }
        409d12
        -        if (safeChars.contains("%")) {
        409d12
        -            throw new IllegalArgumentException("The '%' character cannot be specified as 'safe'");
        409d12
        -        }
        409d12
        -        this.plusForSpace = plusForSpace;
        409d12
        -        this.safeOctets = createSafeOctets(safeChars);
        409d12
        -    }
        409d12
        -
        409d12
        -    /**
        409d12
        -     * Creates a boolean[] with entries corresponding to the character values
        409d12
        -     * for 0-9, A-Z, a-z and those specified in safeChars set to true. The array
        409d12
        -     * is as small as is required to hold the given character information.
        409d12
        -     */
        409d12
        -    private static boolean[] createSafeOctets(String safeChars) {
        409d12
        -        int maxChar = 'z';
        409d12
        -        char[] safeCharArray = safeChars.toCharArray();
        409d12
        -        for (char c : safeCharArray) {
        409d12
        -            maxChar = Math.max(c, maxChar);
        409d12
        -        }
        409d12
        -        boolean[] octets = new boolean[maxChar + 1];
        409d12
        -        for (int c = '0'; c <= '9'; c++) {
        409d12
        -            octets[c] = true;
        409d12
        -        }
        409d12
        -        for (int c = 'A'; c <= 'Z'; c++) {
        409d12
        -            octets[c] = true;
        409d12
        -        }
        409d12
        -        for (int c = 'a'; c <= 'z'; c++) {
        409d12
        -            octets[c] = true;
        409d12
        -        }
        409d12
        -        for (char c : safeCharArray) {
        409d12
        -            octets[c] = true;
        409d12
        -        }
        409d12
        -        return octets;
        409d12
        -    }
        409d12
        -
        409d12
        -    /*
        409d12
        -     * Overridden for performance. For unescaped strings this improved the
        409d12
        -     * performance of the uri escaper from ~760ns to ~400ns as measured by
        409d12
        -     * {@link CharEscapersBenchmark}.
        409d12
        -     */
        409d12
        -    @Override
        409d12
        -    protected int nextEscapeIndex(CharSequence csq, int index, int end) {
        409d12
        -        for (; index < end; index++) {
        409d12
        -            char c = csq.charAt(index);
        409d12
        -            if (c >= safeOctets.length || !safeOctets[c]) {
        409d12
        -                break;
        409d12
        -            }
        409d12
        -        }
        409d12
        -        return index;
        409d12
        -    }
        409d12
        -
        409d12
        -    /*
        409d12
        -     * Overridden for performance. For unescaped strings this improved the
        409d12
        -     * performance of the uri escaper from ~400ns to ~170ns as measured by
        409d12
        -     * {@link CharEscapersBenchmark}.
        409d12
        -     */
        409d12
        -    @Override
        409d12
        -    public String escape(String s) {
        409d12
        -        int slen = s.length();
        409d12
        -        for (int index = 0; index < slen; index++) {
        409d12
        -            char c = s.charAt(index);
        409d12
        -            if (c >= safeOctets.length || !safeOctets[c]) {
        409d12
        -                return escapeSlow(s, index);
        409d12
        -            }
        409d12
        -        }
        409d12
        -        return s;
        409d12
        -    }
        409d12
        -
        409d12
        -    /**
        409d12
        -     * Escapes the given Unicode code point in UTF-8.
        409d12
        -     */
        409d12
        -    @Override
        409d12
        -    protected char[] escape(int cp) {
        409d12
        -        // We should never get negative values here but if we do it will throw
        409d12
        -        // an
        409d12
        -        // IndexOutOfBoundsException, so at least it will get spotted.
        409d12
        -        if (cp < safeOctets.length && safeOctets[cp]) {
        409d12
        -            return null;
        409d12
        -        } else if (cp == ' ' && plusForSpace) {
        409d12
        -            return URI_ESCAPED_SPACE;
        409d12
        -        } else if (cp <= 0x7F) {
        409d12
        -            // Single byte UTF-8 characters
        409d12
        -            // Start with "%--" and fill in the blanks
        409d12
        -            char[] dest = new char[3];
        409d12
        -            dest[0] = '%';
        409d12
        -            dest[2] = UPPER_HEX_DIGITS[cp & 0xF];
        409d12
        -            dest[1] = UPPER_HEX_DIGITS[cp >>> 4];
        409d12
        -            return dest;
        409d12
        -        } else if (cp <= 0x7ff) {
        409d12
        -            // Two byte UTF-8 characters [cp >= 0x80 && cp <= 0x7ff]
        409d12
        -            // Start with "%--%--" and fill in the blanks
        409d12
        -            char[] dest = new char[6];
        409d12
        -            dest[0] = '%';
        409d12
        -            dest[3] = '%';
        409d12
        -            dest[5] = UPPER_HEX_DIGITS[cp & 0xF];
        409d12
        -            cp >>>= 4;
        409d12
        -            dest[4] = UPPER_HEX_DIGITS[0x8 | (cp & 0x3)];
        409d12
        -            cp >>>= 2;
        409d12
        -            dest[2] = UPPER_HEX_DIGITS[cp & 0xF];
        409d12
        -            cp >>>= 4;
        409d12
        -            dest[1] = UPPER_HEX_DIGITS[0xC | cp];
        409d12
        -            return dest;
        409d12
        -        } else if (cp <= 0xffff) {
        409d12
        -            // Three byte UTF-8 characters [cp >= 0x800 && cp <= 0xffff]
        409d12
        -            // Start with "%E-%--%--" and fill in the blanks
        409d12
        -            char[] dest = new char[9];
        409d12
        -            dest[0] = '%';
        409d12
        -            dest[1] = 'E';
        409d12
        -            dest[3] = '%';
        409d12
        -            dest[6] = '%';
        409d12
        -            dest[8] = UPPER_HEX_DIGITS[cp & 0xF];
        409d12
        -            cp >>>= 4;
        409d12
        -            dest[7] = UPPER_HEX_DIGITS[0x8 | (cp & 0x3)];
        409d12
        -            cp >>>= 2;
        409d12
        -            dest[5] = UPPER_HEX_DIGITS[cp & 0xF];
        409d12
        -            cp >>>= 4;
        409d12
        -            dest[4] = UPPER_HEX_DIGITS[0x8 | (cp & 0x3)];
        409d12
        -            cp >>>= 2;
        409d12
        -            dest[2] = UPPER_HEX_DIGITS[cp];
        409d12
        -            return dest;
        409d12
        -        } else if (cp <= 0x10ffff) {
        409d12
        -            char[] dest = new char[12];
        409d12
        -            // Four byte UTF-8 characters [cp >= 0xffff && cp <= 0x10ffff]
        409d12
        -            // Start with "%F-%--%--%--" and fill in the blanks
        409d12
        -            dest[0] = '%';
        409d12
        -            dest[1] = 'F';
        409d12
        -            dest[3] = '%';
        409d12
        -            dest[6] = '%';
        409d12
        -            dest[9] = '%';
        409d12
        -            dest[11] = UPPER_HEX_DIGITS[cp & 0xF];
        409d12
        -            cp >>>= 4;
        409d12
        -            dest[10] = UPPER_HEX_DIGITS[0x8 | (cp & 0x3)];
        409d12
        -            cp >>>= 2;
        409d12
        -            dest[8] = UPPER_HEX_DIGITS[cp & 0xF];
        409d12
        -            cp >>>= 4;
        409d12
        -            dest[7] = UPPER_HEX_DIGITS[0x8 | (cp & 0x3)];
        409d12
        -            cp >>>= 2;
        409d12
        -            dest[5] = UPPER_HEX_DIGITS[cp & 0xF];
        409d12
        -            cp >>>= 4;
        409d12
        -            dest[4] = UPPER_HEX_DIGITS[0x8 | (cp & 0x3)];
        409d12
        -            cp >>>= 2;
        409d12
        -            dest[2] = UPPER_HEX_DIGITS[cp & 0x7];
        409d12
        -            return dest;
        409d12
        -        } else {
        409d12
        -            // If this ever happens it is due to bug in UnicodeEscaper, not bad
        409d12
        -            // input.
        409d12
        -            throw new IllegalArgumentException("Invalid unicode character value " + cp);
        409d12
        -        }
        409d12
        -    }
        409d12
        -}
        409d12
        diff --git a/src/main/java/org/yaml/snakeyaml/external/com/google/gdata/util/common/base/UnicodeEscaper.java b/src/main/java/org/yaml/snakeyaml/external/com/google/gdata/util/common/base/UnicodeEscaper.java
        409d12
        deleted file mode 100644
        409d12
        index 5403185..0000000
        409d12
        --- a/src/main/java/org/yaml/snakeyaml/external/com/google/gdata/util/common/base/UnicodeEscaper.java
        409d12
        +++ /dev/null
        409d12
        @@ -1,506 +0,0 @@
        409d12
        -/* Copyright (c) 2008 Google Inc.
        409d12
        - *
        409d12
        - * Licensed under the Apache License, Version 2.0 (the "License");
        409d12
        - * you may not use this file except in compliance with the License.
        409d12
        - * You may obtain a copy of the License at
        409d12
        - *
        409d12
        - *     http://www.apache.org/licenses/LICENSE-2.0
        409d12
        - *
        409d12
        - * Unless required by applicable law or agreed to in writing, software
        409d12
        - * distributed under the License is distributed on an "AS IS" BASIS,
        409d12
        - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
        409d12
        - * See the License for the specific language governing permissions and
        409d12
        - * limitations under the License.
        409d12
        - */
        409d12
        -
        409d12
        -package org.yaml.snakeyaml.external.com.google.gdata.util.common.base;
        409d12
        -
        409d12
        -import java.io.IOException;
        409d12
        -
        409d12
        -/**
        409d12
        - * An {@link Escaper} that converts literal text into a format safe for
        409d12
        - * inclusion in a particular context (such as an XML document). Typically (but
        409d12
        - * not always), the inverse process of "unescaping" the text is performed
        409d12
        - * automatically by the relevant parser.
        409d12
        - * 
        409d12
        - * 

        409d12
        - * For example, an XML escaper would convert the literal string
        409d12
        - * {@code "Foo<Bar>"} into {@code "Foo<Bar>"} to prevent {@code "<Bar>"}
        409d12
        - * from being confused with an XML tag. When the resulting XML document is
        409d12
        - * parsed, the parser API will return this text as the original literal string
        409d12
        - * {@code "Foo<Bar>"}.
        409d12
        - * 
        409d12
        - * 

        409d12
        - * Note: This class is similar to {@link CharEscaper} but with one very
        409d12
        - * important difference. A CharEscaper can only process Java 
        409d12
        - * href="http://en.wikipedia.org/wiki/UTF-16">UTF16 characters in isolation
        409d12
        - * and may not cope when it encounters surrogate pairs. This class facilitates
        409d12
        - * the correct escaping of all Unicode characters.
        409d12
        - * 
        409d12
        - * 

        409d12
        - * As there are important reasons, including potential security issues, to
        409d12
        - * handle Unicode correctly if you are considering implementing a new escaper
        409d12
        - * you should favor using UnicodeEscaper wherever possible.
        409d12
        - * 
        409d12
        - * 

        409d12
        - * A {@code UnicodeEscaper} instance is required to be stateless, and safe when
        409d12
        - * used concurrently by multiple threads.
        409d12
        - * 
        409d12
        - * 

        409d12
        - * Several popular escapers are defined as constants in the class
        409d12
        - * {@link CharEscapers}. To create your own escapers extend this class and
        409d12
        - * implement the {@link #escape(int)} method.
        409d12
        - * 
        409d12
        - * 
        409d12
        - */
        409d12
        -public abstract class UnicodeEscaper implements Escaper {
        409d12
        -    /** The amount of padding (chars) to use when growing the escape buffer. */
        409d12
        -    private static final int DEST_PAD = 32;
        409d12
        -
        409d12
        -    /**
        409d12
        -     * Returns the escaped form of the given Unicode code point, or {@code null}
        409d12
        -     * if this code point does not need to be escaped. When called as part of an
        409d12
        -     * escaping operation, the given code point is guaranteed to be in the range
        409d12
        -     * {@code 0 <= cp <= Character#MAX_CODE_POINT}.
        409d12
        -     * 
        409d12
        -     * 

        409d12
        -     * If an empty array is returned, this effectively strips the input
        409d12
        -     * character from the resulting text.
        409d12
        -     * 
        409d12
        -     * 

        409d12
        -     * If the character does not need to be escaped, this method should return
        409d12
        -     * {@code null}, rather than an array containing the character
        409d12
        -     * representation of the code point. This enables the escaping algorithm to
        409d12
        -     * perform more efficiently.
        409d12
        -     * 
        409d12
        -     * 

        409d12
        -     * If the implementation of this method cannot correctly handle a particular
        409d12
        -     * code point then it should either throw an appropriate runtime exception
        409d12
        -     * or return a suitable replacement character. It must never silently
        409d12
        -     * discard invalid input as this may constitute a security risk.
        409d12
        -     * 
        409d12
        -     * @param cp
        409d12
        -     *            the Unicode code point to escape if necessary
        409d12
        -     * @return the replacement characters, or {@code null} if no escaping was
        409d12
        -     *         needed
        409d12
        -     */
        409d12
        -    protected abstract char[] escape(int cp);
        409d12
        -
        409d12
        -    /**
        409d12
        -     * Scans a sub-sequence of characters from a given {@link CharSequence},
        409d12
        -     * returning the index of the next character that requires escaping.
        409d12
        -     * 
        409d12
        -     * 

        409d12
        -     * Note: When implementing an escaper, it is a good idea to override
        409d12
        -     * this method for efficiency. The base class implementation determines
        409d12
        -     * successive Unicode code points and invokes {@link #escape(int)} for each
        409d12
        -     * of them. If the semantics of your escaper are such that code points in
        409d12
        -     * the supplementary range are either all escaped or all unescaped, this
        409d12
        -     * method can be implemented more efficiently using
        409d12
        -     * {@link CharSequence#charAt(int)}.
        409d12
        -     * 
        409d12
        -     * 

        409d12
        -     * Note however that if your escaper does not escape characters in the
        409d12
        -     * supplementary range, you should either continue to validate the
        409d12
        -     * correctness of any surrogate characters encountered or provide a clear
        409d12
        -     * warning to users that your escaper does not validate its input.
        409d12
        -     * 
        409d12
        -     * 

        409d12
        -     * See {@link PercentEscaper} for an example.
        409d12
        -     * 
        409d12
        -     * @param csq
        409d12
        -     *            a sequence of characters
        409d12
        -     * @param start
        409d12
        -     *            the index of the first character to be scanned
        409d12
        -     * @param end
        409d12
        -     *            the index immediately after the last character to be scanned
        409d12
        -     * @throws IllegalArgumentException
        409d12
        -     *             if the scanned sub-sequence of {@code csq} contains invalid
        409d12
        -     *             surrogate pairs
        409d12
        -     */
        409d12
        -    protected int nextEscapeIndex(CharSequence csq, int start, int end) {
        409d12
        -        int index = start;
        409d12
        -        while (index < end) {
        409d12
        -            int cp = codePointAt(csq, index, end);
        409d12
        -            if (cp < 0 || escape(cp) != null) {
        409d12
        -                break;
        409d12
        -            }
        409d12
        -            index += Character.isSupplementaryCodePoint(cp) ? 2 : 1;
        409d12
        -        }
        409d12
        -        return index;
        409d12
        -    }
        409d12
        -
        409d12
        -    /**
        409d12
        -     * Returns the escaped form of a given literal string.
        409d12
        -     * 
        409d12
        -     * 

        409d12
        -     * If you are escaping input in arbitrary successive chunks, then it is not
        409d12
        -     * generally safe to use this method. If an input string ends with an
        409d12
        -     * unmatched high surrogate character, then this method will throw
        409d12
        -     * {@link IllegalArgumentException}. You should either ensure your input is
        409d12
        -     * valid UTF-16 before
        409d12
        -     * calling this method or use an escaped {@link Appendable} (as returned by
        409d12
        -     * {@link #escape(Appendable)}) which can cope with arbitrarily split input.
        409d12
        -     * 
        409d12
        -     * 

        409d12
        -     * Note: When implementing an escaper it is a good idea to override
        409d12
        -     * this method for efficiency by inlining the implementation of
        409d12
        -     * {@link #nextEscapeIndex(CharSequence, int, int)} directly. Doing this for
        409d12
        -     * {@link PercentEscaper} more than doubled the performance for unescaped
        409d12
        -     * strings (as measured by {@link CharEscapersBenchmark}).
        409d12
        -     * 
        409d12
        -     * @param string
        409d12
        -     *            the literal string to be escaped
        409d12
        -     * @return the escaped form of {@code string}
        409d12
        -     * @throws NullPointerException
        409d12
        -     *             if {@code string} is null
        409d12
        -     * @throws IllegalArgumentException
        409d12
        -     *             if invalid surrogate characters are encountered
        409d12
        -     */
        409d12
        -    public String escape(String string) {
        409d12
        -        int end = string.length();
        409d12
        -        int index = nextEscapeIndex(string, 0, end);
        409d12
        -        return index == end ? string : escapeSlow(string, index);
        409d12
        -    }
        409d12
        -
        409d12
        -    /**
        409d12
        -     * Returns the escaped form of a given literal string, starting at the given
        409d12
        -     * index. This method is called by the {@link #escape(String)} method when
        409d12
        -     * it discovers that escaping is required. It is protected to allow
        409d12
        -     * subclasses to override the fastpath escaping function to inline their
        409d12
        -     * escaping test. See {@link CharEscaperBuilder} for an example usage.
        409d12
        -     * 
        409d12
        -     * 

        409d12
        -     * This method is not reentrant and may only be invoked by the top level
        409d12
        -     * {@link #escape(String)} method.
        409d12
        -     * 
        409d12
        -     * @param s
        409d12
        -     *            the literal string to be escaped
        409d12
        -     * @param index
        409d12
        -     *            the index to start escaping from
        409d12
        -     * @return the escaped form of {@code string}
        409d12
        -     * @throws NullPointerException
        409d12
        -     *             if {@code string} is null
        409d12
        -     * @throws IllegalArgumentException
        409d12
        -     *             if invalid surrogate characters are encountered
        409d12
        -     */
        409d12
        -    protected final String escapeSlow(String s, int index) {
        409d12
        -        int end = s.length();
        409d12
        -
        409d12
        -        // Get a destination buffer and setup some loop variables.
        409d12
        -        char[] dest = DEST_TL.get();
        409d12
        -        int destIndex = 0;
        409d12
        -        int unescapedChunkStart = 0;
        409d12
        -
        409d12
        -        while (index < end) {
        409d12
        -            int cp = codePointAt(s, index, end);
        409d12
        -            if (cp < 0) {
        409d12
        -                throw new IllegalArgumentException("Trailing high surrogate at end of input");
        409d12
        -            }
        409d12
        -            char[] escaped = escape(cp);
        409d12
        -            if (escaped != null) {
        409d12
        -                int charsSkipped = index - unescapedChunkStart;
        409d12
        -
        409d12
        -                // This is the size needed to add the replacement, not the full
        409d12
        -                // size needed by the string. We only regrow when we absolutely
        409d12
        -                // must.
        409d12
        -                int sizeNeeded = destIndex + charsSkipped + escaped.length;
        409d12
        -                if (dest.length < sizeNeeded) {
        409d12
        -                    int destLength = sizeNeeded + (end - index) + DEST_PAD;
        409d12
        -                    dest = growBuffer(dest, destIndex, destLength);
        409d12
        -                }
        409d12
        -                // If we have skipped any characters, we need to copy them now.
        409d12
        -                if (charsSkipped > 0) {
        409d12
        -                    s.getChars(unescapedChunkStart, index, dest, destIndex);
        409d12
        -                    destIndex += charsSkipped;
        409d12
        -                }
        409d12
        -                if (escaped.length > 0) {
        409d12
        -                    System.arraycopy(escaped, 0, dest, destIndex, escaped.length);
        409d12
        -                    destIndex += escaped.length;
        409d12
        -                }
        409d12
        -            }
        409d12
        -            unescapedChunkStart = index + (Character.isSupplementaryCodePoint(cp) ? 2 : 1);
        409d12
        -            index = nextEscapeIndex(s, unescapedChunkStart, end);
        409d12
        -        }
        409d12
        -
        409d12
        -        // Process trailing unescaped characters - no need to account for
        409d12
        -        // escaped
        409d12
        -        // length or padding the allocation.
        409d12
        -        int charsSkipped = end - unescapedChunkStart;
        409d12
        -        if (charsSkipped > 0) {
        409d12
        -            int endIndex = destIndex + charsSkipped;
        409d12
        -            if (dest.length < endIndex) {
        409d12
        -                dest = growBuffer(dest, destIndex, endIndex);
        409d12
        -            }
        409d12
        -            s.getChars(unescapedChunkStart, end, dest, destIndex);
        409d12
        -            destIndex = endIndex;
        409d12
        -        }
        409d12
        -        return new String(dest, 0, destIndex);
        409d12
        -    }
        409d12
        -
        409d12
        -    /**
        409d12
        -     * Returns an {@code Appendable} instance which automatically escapes all
        409d12
        -     * text appended to it before passing the resulting text to an underlying
        409d12
        -     * {@code Appendable}.
        409d12
        -     * 
        409d12
        -     * 

        409d12
        -     * Unlike {@link #escape(String)} it is permitted to append arbitrarily
        409d12
        -     * split input to this Appendable, including input that is split over a
        409d12
        -     * surrogate pair. In this case the pending high surrogate character will
        409d12
        -     * not be processed until the corresponding low surrogate is appended. This
        409d12
        -     * means that a trailing high surrogate character at the end of the input
        409d12
        -     * cannot be detected and will be silently ignored. This is unavoidable
        409d12
        -     * since the Appendable interface has no {@code close()} method, and it is
        409d12
        -     * impossible to determine when the last characters have been appended.
        409d12
        -     * 
        409d12
        -     * 

        409d12
        -     * The methods of the returned object will propagate any exceptions thrown
        409d12
        -     * by the underlying {@code Appendable}.
        409d12
        -     * 
        409d12
        -     * 

        409d12
        -     * For well formed UTF-16
        409d12
        -     * the escaping behavior is identical to that of {@link #escape(String)} and
        409d12
        -     * the following code is equivalent to (but much slower than)
        409d12
        -     * {@code escaper.escape(string)}:
        409d12
        -     * 
        409d12
        -     * 
        409d12
        -     * {
        409d12
        -     *     @code
        409d12
        -     *     StringBuilder sb = new StringBuilder();
        409d12
        -     *     escaper.escape(sb).append(string);
        409d12
        -     *     return sb.toString();
        409d12
        -     * }
        409d12
        -     * 
        409d12
        -     * 
        409d12
        -     * @param out
        409d12
        -     *            the underlying {@code Appendable} to append escaped output to
        409d12
        -     * @return an {@code Appendable} which passes text to {@code out} after
        409d12
        -     *         escaping it
        409d12
        -     * @throws NullPointerException
        409d12
        -     *             if {@code out} is null
        409d12
        -     * @throws IllegalArgumentException
        409d12
        -     *             if invalid surrogate characters are encountered
        409d12
        -     * 
        409d12
        -     */
        409d12
        -    public Appendable escape(final Appendable out) {
        409d12
        -        assert out != null;
        409d12
        -
        409d12
        -        return new Appendable() {
        409d12
        -            int pendingHighSurrogate = -1;
        409d12
        -            char[] decodedChars = new char[2];
        409d12
        -
        409d12
        -            public Appendable append(CharSequence csq) throws IOException {
        409d12
        -                return append(csq, 0, csq.length());
        409d12
        -            }
        409d12
        -
        409d12
        -            public Appendable append(CharSequence csq, int start, int end) throws IOException {
        409d12
        -                int index = start;
        409d12
        -                if (index < end) {
        409d12
        -                    // This is a little subtle: index must never reference the
        409d12
        -                    // middle of a
        409d12
        -                    // surrogate pair but unescapedChunkStart can. The first
        409d12
        -                    // time we enter
        409d12
        -                    // the loop below it is possible that index !=
        409d12
        -                    // unescapedChunkStart.
        409d12
        -                    int unescapedChunkStart = index;
        409d12
        -                    if (pendingHighSurrogate != -1) {
        409d12
        -                        // Our last append operation ended halfway through a
        409d12
        -                        // surrogate pair
        409d12
        -                        // so we have to do some extra work first.
        409d12
        -                        char c = csq.charAt(index++);
        409d12
        -                        if (!Character.isLowSurrogate(c)) {
        409d12
        -                            throw new IllegalArgumentException(
        409d12
        -                                    "Expected low surrogate character but got " + c);
        409d12
        -                        }
        409d12
        -                        char[] escaped = escape(Character.toCodePoint((char) pendingHighSurrogate,
        409d12
        -                                c));
        409d12
        -                        if (escaped != null) {
        409d12
        -                            // Emit the escaped character and adjust
        409d12
        -                            // unescapedChunkStart to
        409d12
        -                            // skip the low surrogate we have consumed.
        409d12
        -                            outputChars(escaped, escaped.length);
        409d12
        -                            unescapedChunkStart += 1;
        409d12
        -                        } else {
        409d12
        -                            // Emit pending high surrogate (unescaped) but do
        409d12
        -                            // not modify
        409d12
        -                            // unescapedChunkStart as we must still emit the low
        409d12
        -                            // surrogate.
        409d12
        -                            out.append((char) pendingHighSurrogate);
        409d12
        -                        }
        409d12
        -                        pendingHighSurrogate = -1;
        409d12
        -                    }
        409d12
        -                    while (true) {
        409d12
        -                        // Find and append the next subsequence of unescaped
        409d12
        -                        // characters.
        409d12
        -                        index = nextEscapeIndex(csq, index, end);
        409d12
        -                        if (index > unescapedChunkStart) {
        409d12
        -                            out.append(csq, unescapedChunkStart, index);
        409d12
        -                        }
        409d12
        -                        if (index == end) {
        409d12
        -                            break;
        409d12
        -                        }
        409d12
        -                        // If we are not finished, calculate the next code
        409d12
        -                        // point.
        409d12
        -                        int cp = codePointAt(csq, index, end);
        409d12
        -                        if (cp < 0) {
        409d12
        -                            // Our sequence ended half way through a surrogate
        409d12
        -                            // pair so just
        409d12
        -                            // record the state and exit.
        409d12
        -                            pendingHighSurrogate = -cp;
        409d12
        -                            break;
        409d12
        -                        }
        409d12
        -                        // Escape the code point and output the characters.
        409d12
        -                        char[] escaped = escape(cp);
        409d12
        -                        if (escaped != null) {
        409d12
        -                            outputChars(escaped, escaped.length);
        409d12
        -                        } else {
        409d12
        -                            // This shouldn't really happen if nextEscapeIndex
        409d12
        -                            // is correct but
        409d12
        -                            // we should cope with false positives.
        409d12
        -                            int len = Character.toChars(cp, decodedChars, 0);
        409d12
        -                            outputChars(decodedChars, len);
        409d12
        -                        }
        409d12
        -                        // Update our index past the escaped character and
        409d12
        -                        // continue.
        409d12
        -                        index += (Character.isSupplementaryCodePoint(cp) ? 2 : 1);
        409d12
        -                        unescapedChunkStart = index;
        409d12
        -                    }
        409d12
        -                }
        409d12
        -                return this;
        409d12
        -            }
        409d12
        -
        409d12
        -            public Appendable append(char c) throws IOException {
        409d12
        -                if (pendingHighSurrogate != -1) {
        409d12
        -                    // Our last append operation ended halfway through a
        409d12
        -                    // surrogate pair
        409d12
        -                    // so we have to do some extra work first.
        409d12
        -                    if (!Character.isLowSurrogate(c)) {
        409d12
        -                        throw new IllegalArgumentException(
        409d12
        -                                "Expected low surrogate character but got '" + c + "' with value "
        409d12
        -                                        + (int) c);
        409d12
        -                    }
        409d12
        -                    char[] escaped = escape(Character.toCodePoint((char) pendingHighSurrogate, c));
        409d12
        -                    if (escaped != null) {
        409d12
        -                        outputChars(escaped, escaped.length);
        409d12
        -                    } else {
        409d12
        -                        out.append((char) pendingHighSurrogate);
        409d12
        -                        out.append(c);
        409d12
        -                    }
        409d12
        -                    pendingHighSurrogate = -1;
        409d12
        -                } else if (Character.isHighSurrogate(c)) {
        409d12
        -                    // This is the start of a (split) surrogate pair.
        409d12
        -                    pendingHighSurrogate = c;
        409d12
        -                } else {
        409d12
        -                    if (Character.isLowSurrogate(c)) {
        409d12
        -                        throw new IllegalArgumentException("Unexpected low surrogate character '"
        409d12
        -                                + c + "' with value " + (int) c);
        409d12
        -                    }
        409d12
        -                    // This is a normal (non surrogate) char.
        409d12
        -                    char[] escaped = escape(c);
        409d12
        -                    if (escaped != null) {
        409d12
        -                        outputChars(escaped, escaped.length);
        409d12
        -                    } else {
        409d12
        -                        out.append(c);
        409d12
        -                    }
        409d12
        -                }
        409d12
        -                return this;
        409d12
        -            }
        409d12
        -
        409d12
        -            private void outputChars(char[] chars, int len) throws IOException {
        409d12
        -                for (int n = 0; n < len; n++) {
        409d12
        -                    out.append(chars[n]);
        409d12
        -                }
        409d12
        -            }
        409d12
        -        };
        409d12
        -    }
        409d12
        -
        409d12
        -    /**
        409d12
        -     * Returns the Unicode code point of the character at the given index.
        409d12
        -     * 
        409d12
        -     * 

        409d12
        -     * Unlike {@link Character#codePointAt(CharSequence, int)} or
        409d12
        -     * {@link String#codePointAt(int)} this method will never fail silently when
        409d12
        -     * encountering an invalid surrogate pair.
        409d12
        -     * 
        409d12
        -     * 

        409d12
        -     * The behaviour of this method is as follows:
        409d12
        -     * 
          409d12
          -     * 
        1. If {@code index >= end}, {@link IndexOutOfBoundsException} is thrown.
        2. 409d12
          -     * 
        3. If the character at the specified index is not a surrogate, it is
        4. 409d12
          -     * returned.
          409d12
          -     * 
        5. If the first character was a high surrogate value, then an attempt is
        6. 409d12
          -     * made to read the next character.
          409d12
          -     * 
            409d12
            -     * 
          1. If the end of the sequence was reached, the negated value of the
          2. 409d12
            -     * trailing high surrogate is returned.
            409d12
            -     * 
          3. If the next character was a valid low surrogate, the code point
          4. 409d12
            -     * value of the high/low surrogate pair is returned.
            409d12
            -     * 
          5. If the next character was not a low surrogate value, then
          6. 409d12
            -     * {@link IllegalArgumentException} is thrown.
            409d12
            -     * 
            409d12
            -     * 
          7. If the first character was a low surrogate value,
          8. 409d12
            -     * {@link IllegalArgumentException} is thrown.
            409d12
            -     * 
            409d12
            -     * 
            409d12
            -     * @param seq
            409d12
            -     *            the sequence of characters from which to decode the code point
            409d12
            -     * @param index
            409d12
            -     *            the index of the first character to decode
            409d12
            -     * @param end
            409d12
            -     *            the index beyond the last valid character to decode
            409d12
            -     * @return the Unicode code point for the given index or the negated value
            409d12
            -     *         of the trailing high surrogate character at the end of the
            409d12
            -     *         sequence
            409d12
            -     */
            409d12
            -    protected static final int codePointAt(CharSequence seq, int index, int end) {
            409d12
            -        if (index < end) {
            409d12
            -            char c1 = seq.charAt(index++);
            409d12
            -            if (c1 < Character.MIN_HIGH_SURROGATE || c1 > Character.MAX_LOW_SURROGATE) {
            409d12
            -                // Fast path (first test is probably all we need to do)
            409d12
            -                return c1;
            409d12
            -            } else if (c1 <= Character.MAX_HIGH_SURROGATE) {
            409d12
            -                // If the high surrogate was the last character, return its
            409d12
            -                // inverse
            409d12
            -                if (index == end) {
            409d12
            -                    return -c1;
            409d12
            -                }
            409d12
            -                // Otherwise look for the low surrogate following it
            409d12
            -                char c2 = seq.charAt(index);
            409d12
            -                if (Character.isLowSurrogate(c2)) {
            409d12
            -                    return Character.toCodePoint(c1, c2);
            409d12
            -                }
            409d12
            -                throw new IllegalArgumentException("Expected low surrogate but got char '" + c2
            409d12
            -                        + "' with value " + (int) c2 + " at index " + index);
            409d12
            -            } else {
            409d12
            -                throw new IllegalArgumentException("Unexpected low surrogate character '" + c1
            409d12
            -                        + "' with value " + (int) c1 + " at index " + (index - 1));
            409d12
            -            }
            409d12
            -        }
            409d12
            -        throw new IndexOutOfBoundsException("Index exceeds specified range");
            409d12
            -    }
            409d12
            -
            409d12
            -    /**
            409d12
            -     * Helper method to grow the character buffer as needed, this only happens
            409d12
            -     * once in a while so it's ok if it's in a method call. If the index passed
            409d12
            -     * in is 0 then no copying will be done.
            409d12
            -     */
            409d12
            -    private static final char[] growBuffer(char[] dest, int index, int size) {
            409d12
            -        char[] copy = new char[size];
            409d12
            -        if (index > 0) {
            409d12
            -            System.arraycopy(dest, 0, copy, 0, index);
            409d12
            -        }
            409d12
            -        return copy;
            409d12
            -    }
            409d12
            -
            409d12
            -    /**
            409d12
            -     * A thread-local destination buffer to keep us from creating new buffers.
            409d12
            -     * The starting size is 1024 characters. If we grow past this we don't put
            409d12
            -     * it back in the threadlocal, we just keep going and grow as needed.
            409d12
            -     */
            409d12
            -    private static final ThreadLocal<char[]> DEST_TL = new ThreadLocal<char[]>() {
            409d12
            -        @Override
            409d12
            -        protected char[] initialValue() {
            409d12
            -            return new char[1024];
            409d12
            -        }
            409d12
            -    };
            409d12
            -}
            409d12
            diff --git a/src/main/java/org/yaml/snakeyaml/util/UriEncoder.java b/src/main/java/org/yaml/snakeyaml/util/UriEncoder.java
            409d12
            index e23904f..f266387 100644
            409d12
            --- a/src/main/java/org/yaml/snakeyaml/util/UriEncoder.java
            409d12
            +++ b/src/main/java/org/yaml/snakeyaml/util/UriEncoder.java
            409d12
            @@ -23,25 +23,46 @@ import java.nio.charset.CharacterCodingException;
            409d12
             import java.nio.charset.Charset;
            409d12
             import java.nio.charset.CharsetDecoder;
            409d12
             import java.nio.charset.CodingErrorAction;
            409d12
            +import java.util.BitSet;
            409d12
             
            409d12
            +import org.apache.commons.codec.net.URLCodec;
            409d12
             import org.yaml.snakeyaml.error.YAMLException;
            409d12
            -import org.yaml.snakeyaml.external.com.google.gdata.util.common.base.Escaper;
            409d12
            -import org.yaml.snakeyaml.external.com.google.gdata.util.common.base.PercentEscaper;
            409d12
            +
            409d12
             
            409d12
             public abstract class UriEncoder {
            409d12
                 private static final CharsetDecoder UTF8Decoder = Charset.forName("UTF-8").newDecoder()
            409d12
                         .onMalformedInput(CodingErrorAction.REPORT);
            409d12
            -    // Include the [] chars to the SAFEPATHCHARS_URLENCODER to avoid
            409d12
            -    // its escape as required by spec. See
            409d12
            -    // http://yaml.org/spec/1.1/#escaping%20in%20URI/
            409d12
            -    private static final String SAFE_CHARS = PercentEscaper.SAFEPATHCHARS_URLENCODER + "[]/";
            409d12
            -    private static final Escaper escaper = new PercentEscaper(SAFE_CHARS, false);
            409d12
            +
            409d12
            +    // default safe characters which can appear within URI and shouldn't be escaped
            409d12
            +    private static final BitSet allowedCharacters = new BitSet(256);
            409d12
            +
            409d12
            +    static {
            409d12
            +        for (int i = 'a'; i <= 'z'; i++) {
            409d12
            +            allowedCharacters.set(i);
            409d12
            +        }
            409d12
            +        for (int i = 'A'; i <= 'Z'; i++) {
            409d12
            +            allowedCharacters.set(i);
            409d12
            +        }
            409d12
            +        for (int i = '0'; i <= '9'; i++) {
            409d12
            +            allowedCharacters.set(i);
            409d12
            +        }
            409d12
            +        // http://yaml.org/spec/1.1/#escaping%20in%20URI/
            409d12
            +        for (char c : "-_.!~*'()@:$&,;=/[]".toCharArray()) {
            409d12
            +            allowedCharacters.set(c);
            409d12
            +        }
            409d12
            +    }
            409d12
             
            409d12
                 /**
            409d12
                  * Escape special characters with '%'
            409d12
                  */
            409d12
                 public static String encode(String uri) {
            409d12
            -        return escaper.escape(uri);
            409d12
            +        try {
            409d12
            +            byte[] rawdata = URLCodec.encodeUrl(allowedCharacters,
            409d12
            +                    uri.getBytes("UTF-8"));
            409d12
            +            return new String(rawdata, 0, rawdata.length, "US-ASCII");
            409d12
            +        } catch (UnsupportedEncodingException e) {
            409d12
            +            throw new YAMLException(e);
            409d12
            +        }
            409d12
                 }
            409d12
             
            409d12
                 /**
            409d12
            -- 
            409d12
            2.7.4
            409d12