View | Details | Raw Unified | Return to bug 25382
Collapse All | Expand All

(-)file_not_specified_in_diff (-23 / +36 lines)
Line 157 Link Here
157
                w.print(obj.toString());
157
                w.write(obj.toString());
158
--
Lines 163-165 Link Here
163
                int c;
163
                char[] buf = new char[4096];
164
                while ((c=reader.read()) != -1) {
164
                int count;
165
                    escapeChar((char)c, w);
165
                while ((count=reader.read(buf, 0, 4096)) != -1) {
166
--
166
                    writeEscaped(buf, count, w);
Lines 169-172 Link Here
169
                // avoid needless double-buffering (is this really more efficient?)
170
                int start = 0;
170
                for (int i = 0; i < text.length(); i++) {
171
                //cache the length, avoid to call to String.length()
171
                    char c = text.charAt(i);
172
                int length = text.length();
172
                    escapeChar(c, w);
173
                char[] buf = text.toCharArray();
173
--
174
                writeEscaped(buf,length,w);
Line 176 Link Here
178
    private final static int HIGHEST_SPECIAL = '>'+1;
179
    static char[][] specialCharactersRepresentation = new char[HIGHEST_SPECIAL][];
180
    static {
181
        specialCharactersRepresentation['&'] = "&amp;".toCharArray();
182
        specialCharactersRepresentation['<'] = "&lt;".toCharArray();
183
        specialCharactersRepresentation['>'] = "&gt;".toCharArray();
184
        specialCharactersRepresentation['"'] = "&#034;".toCharArray();
185
        specialCharactersRepresentation['\''] = "&#039;".toCharArray();
186
    }
187
    private static void writeEscaped(char[] buffer, int length, JspWriter w) throws IOException{
188
        int start = 0;
189
        for (int i = 0; i < length; i++) {
190
            char c = buffer[i];
191
            if (c <= HIGHEST_SPECIAL) {
192
                char[] escaped = specialCharactersRepresentation[c];
193
                if (escaped != null) {
194
                    if (start < i) {
195
                        w.write(buffer,start,i-start);
196
                    }
197
                    start = i+1;
198
                    w.write(escaped);
199
                }
200
            }
201
        }
202
        if (start < length) {
203
            w.write(buffer,start,length-start);
Lines 177-190 Link Here
177
    
178
    private static void escapeChar(char c, JspWriter w) throws IOException {
179
        if (c == '&')
180
            w.print("&amp;");
181
        else if (c == '<')
182
            w.print("&lt;");
183
        else if (c == '>')
184
            w.print("&gt;");
185
        else if (c == '"')
186
            w.print("&#034;");
187
        else if (c == '\'')
188
            w.print("&#039;");

Return to bug 25382