~ubuntu-branches/ubuntu/natty/tomcat6/natty-proposed

« back to all changes in this revision

Viewing changes to java/org/apache/jasper/compiler/AttributeParser.java

  • Committer: Bazaar Package Importer
  • Author(s): Thierry Carrez
  • Date: 2010-05-21 13:51:15 UTC
  • mfrom: (2.2.12 sid)
  • Revision ID: james.westby@ubuntu.com-20100521135115-qfwnf24lzvi3644v
Tags: 6.0.26-2
* debian/tomcat6.{postinst,prerm}: Respect TOMCAT6_USER and TOMCAT6_GROUP
  as defined in /etc/default/tomcat6 when setting directory permissions and
  authbind configuration (Closes: #581018, LP: #557300)
* debian/tomcat6.postinst: Use group "tomcat6" instead of "adm" for
  permissions in /var/lib/tomcat6, so that group "adm" doesn't get write
  permissions over /var/lib/tomcat6/webapps (LP: #569118)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 * "\${1+1}". After unquoting, both appear as "${1+1}" but the first should
25
25
 * evaluate to "2" and the second to "${1+1}". Literal \, $ and # need special
26
26
 * treatment to ensure there is no ambiguity. The JSP attribute unquoting
27
 
 * covers \\, \", \', \$, \#, %\>, <\%, &apos; and &quot;
 
27
 * covers \\, \", \', \$, \#, %\&gt;, &lt;\%, &amp;apos; and &amp;quot;
28
28
 */
29
29
public class AttributeParser {
30
30
 
43
43
     *                      scripting expressions.
44
44
     * @param isELIgnored   Is expression language being ignored on the page
45
45
     *                      where the JSP attribute is defined.
 
46
     * @param isDeferredSyntaxAllowedAsLiteral
 
47
     *                      Are deferred expressions treated as literals?
46
48
     * @return              An unquoted JSP attribute that, if it contains
47
49
     *                      expression language can be safely passed to the EL
48
50
     *                      processor without fear of ambiguity.
49
51
     */
50
52
    public static String getUnquoted(String input, char quote,
51
 
            boolean isELIgnored) {
 
53
            boolean isELIgnored, boolean isDeferredSyntaxAllowedAsLiteral) {
52
54
        return (new AttributeParser(input, quote, isELIgnored,
 
55
                isDeferredSyntaxAllowedAsLiteral,
53
56
                STRICT_QUOTE_ESCAPING)).getUnquoted();
54
57
    }
55
58
 
62
65
     *                      scripting expressions.
63
66
     * @param isELIgnored   Is expression language being ignored on the page
64
67
     *                      where the JSP attribute is defined.
 
68
     * @param isDeferredSyntaxAllowedAsLiteral
 
69
     *                      Are deferred expressions treated as literals?
65
70
     * @param strict        The value to use for STRICT_QUOTE_ESCAPING.
66
71
     * @return              An unquoted JSP attribute that, if it contains
67
72
     *                      expression language can be safely passed to the EL
68
73
     *                      processor without fear of ambiguity.
69
74
     */
70
75
    protected static String getUnquoted(String input, char quote,
71
 
            boolean isELIgnored, boolean strict) {
 
76
            boolean isELIgnored, boolean isDeferredSyntaxAllowedAsLiteral,
 
77
            boolean strict) {
72
78
        return (new AttributeParser(input, quote, isELIgnored,
73
 
                strict)).getUnquoted();
 
79
                isDeferredSyntaxAllowedAsLiteral, strict)).getUnquoted();
74
80
    }
75
81
 
76
82
    /* The quoted input string. */
83
89
     * treated as literals rather than quoted values. */
84
90
    private final boolean isELIgnored;
85
91
    
 
92
    /* Are deferred expression treated as literals */
 
93
    private final boolean isDeferredSyntaxAllowedAsLiteral;
 
94
    
86
95
    /* Overrides the STRICT_QUOTE_ESCAPING. Used for Unit tests only. */
87
96
    private final boolean strict;
88
97
    
109
118
     * @param strict
110
119
     */
111
120
    private AttributeParser(String input, char quote,
112
 
            boolean isELIgnored, boolean strict) {
 
121
            boolean isELIgnored, boolean isDeferredSyntaxAllowedAsLiteral,
 
122
            boolean strict) {
113
123
        this.input = input;
114
124
        this.quote = quote;
115
125
        // If quote is null this is a scriptign expressions and any EL syntax
116
126
        // should be ignored
117
127
        this.isELIgnored = isELIgnored || (quote == 0);
 
128
        this.isDeferredSyntaxAllowedAsLiteral =
 
129
            isDeferredSyntaxAllowedAsLiteral;
118
130
        this.strict = strict;
119
131
        this.type = getType(input);
120
132
        this.size = input.length();
151
163
            char ch = nextChar();
152
164
            if (!isELIgnored && ch == '\\') {
153
165
                if (type == 0) {
154
 
                    type = '$';
 
166
                    result.append("\\");
 
167
                } else {
 
168
                    result.append(type);
 
169
                    result.append("{'\\\\'}");
155
170
                }
156
 
                result.append(type);
157
 
                result.append("{'\\\\'}");
158
171
            } else if (!isELIgnored && ch == '$' && lastChEscaped){
159
172
                if (type == 0) {
160
 
                    type = '$';
 
173
                    result.append("\\$");
 
174
                } else {
 
175
                    result.append(type);
 
176
                    result.append("{'$'}");
161
177
                }
162
 
                result.append(type);
163
 
                result.append("{'$'}");
164
178
            } else if (!isELIgnored && ch == '#' && lastChEscaped){
 
179
                // Note if isDeferredSyntaxAllowedAsLiteral==true, \# will
 
180
                // not be treated as an escape
165
181
                if (type == 0) {
166
 
                    type = '$';
 
182
                    result.append("\\#");
 
183
                } else {
 
184
                    result.append(type);
 
185
                    result.append("{'#'}");
167
186
                }
168
 
                result.append(type);
169
 
                result.append("{'#'}");
170
187
            } else if (ch == type){
171
188
                if (i < size) {
172
189
                    char next = input.charAt(i);
197
214
    private void parseEL() {
198
215
        boolean endEL = false;
199
216
        boolean insideLiteral = false;
 
217
        char literalQuote = 0;
200
218
        while (i < size && !endEL) {
201
 
            char literalQuote = '\'';
202
219
            char ch = nextChar();
203
220
            if (ch == '\'' || ch == '\"') {
204
221
                if (insideLiteral) {
261
278
        } else if (ch == '\\' && i + 1 < size) {
262
279
            ch = input.charAt(i + 1);
263
280
            if (ch == '\\' || ch == '\"' || ch == '\'' ||
264
 
                    (!isELIgnored && (ch == '$' || ch == '#'))) {
 
281
                    (!isELIgnored &&
 
282
                            (ch == '$' ||
 
283
                                    (!isDeferredSyntaxAllowedAsLiteral &&
 
284
                                            ch == '#')))) {
265
285
                i += 2;
266
286
                lastChEscaped = true;
267
287
            } else {
311
331
        int j = 0;
312
332
        int len = value.length();
313
333
        char current;
314
 
        
 
334
 
315
335
        while (j < len) {
316
336
            current = value.charAt(j);
317
337
            if (current == '\\') {
318
338
                // Escape character - skip a character
319
339
                j++;
320
 
            } else if (current == '#') {
 
340
            } else if (current == '#' && !isDeferredSyntaxAllowedAsLiteral) {
321
341
                if (j < (len -1) && value.charAt(j + 1) == '{') {
322
342
                    return '#';
323
343
                }