Attachment #534530: wip fix for bug #658949

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

(-)a/netwerk/protocol/data/nsDataChannel.cpp (-2 / +4 lines)
Line     Link Here 
 Lines 57-76   nsDataChannel::OpenContentStream(PRBool Link Here 
57
    NS_ENSURE_TRUE(URI(), NS_ERROR_NOT_INITIALIZED);
57
    NS_ENSURE_TRUE(URI(), NS_ERROR_NOT_INITIALIZED);
58
58
59
    nsresult rv;
59
    nsresult rv;
60
60
61
    nsCAutoString spec;
61
    nsCAutoString spec;
62
    rv = URI()->GetAsciiSpec(spec);
62
    rv = URI()->GetAsciiSpec(spec);
63
    if (NS_FAILED(rv)) return rv;
63
    if (NS_FAILED(rv)) return rv;
64
64
65
    nsCString contentType, contentCharset, dataBuffer;
65
    nsCString contentType, contentCharset, dataBuffer, ref;
66
    PRBool lBase64;
66
    PRBool lBase64;
67
    rv = nsDataHandler::ParseURI(spec, contentType, contentCharset,
67
    rv = nsDataHandler::ParseURI(spec, contentType, contentCharset,
68
                                 lBase64, dataBuffer);
68
                                 lBase64, dataBuffer, ref);
69
70
    // XXXdholbert What should we do with 'ref' here?
69
71
70
    NS_UnescapeURL(dataBuffer);
72
    NS_UnescapeURL(dataBuffer);
71
73
72
    if (lBase64) {
74
    if (lBase64) {
73
        // Don't allow spaces in base64-encoded content. This is only
75
        // Don't allow spaces in base64-encoded content. This is only
74
        // relevant for escaped spaces; other spaces are stripped in
76
        // relevant for escaped spaces; other spaces are stripped in
75
        // NewURI.
77
        // NewURI.
76
        dataBuffer.StripWhitespace();
78
        dataBuffer.StripWhitespace();
(-)a/netwerk/protocol/data/nsDataHandler.cpp (-4 / +20 lines)
Line     Link Here 
 Lines 109-142   nsDataHandler::NewURI(const nsACString & Link Here 
109
        // Looks like a reference instead of a fully-specified URI.
109
        // Looks like a reference instead of a fully-specified URI.
110
        // --> initialize |uri| as a clone of |aBaseURI|, with ref appended.
110
        // --> initialize |uri| as a clone of |aBaseURI|, with ref appended.
111
        rv = aBaseURI->Clone(getter_AddRefs(uri));
111
        rv = aBaseURI->Clone(getter_AddRefs(uri));
112
        if (NS_FAILED(rv))
112
        if (NS_FAILED(rv))
113
            return rv;
113
            return rv;
114
        rv = uri->SetRef(spec);
114
        rv = uri->SetRef(spec);
115
    } else {
115
    } else {
116
        // Otherwise, we'll assume |spec| is a fully-specified data URI
116
        // Otherwise, we'll assume |spec| is a fully-specified data URI
117
        nsCAutoString contentType, contentCharset, dataBuffer;
117
        nsCAutoString contentType, contentCharset, dataBuffer, ref;
118
        PRBool base64;
118
        PRBool base64;
119
        rv = ParseURI(spec, contentType, contentCharset, base64, dataBuffer);
119
        rv = ParseURI(spec, contentType, contentCharset, base64, dataBuffer, ref);
120
        if (NS_FAILED(rv))
120
        if (NS_FAILED(rv))
121
            return rv;
121
            return rv;
122
122
123
        // Strip whitespace unless this is text, where whitespace is important
123
        // Strip whitespace unless this is text, where whitespace is important
124
        // Don't strip escaped whitespace though (bug 391951)
124
        // Don't strip escaped whitespace though (bug 391951)
125
        if (base64 || (strncmp(contentType.get(),"text/",5) != 0 &&
125
        if (base64 || (strncmp(contentType.get(),"text/",5) != 0 &&
126
                       contentType.Find("xml") == kNotFound)) {
126
                       contentType.Find("xml") == kNotFound)) {
127
            // it's ascii encoded binary, don't let any spaces in
127
            // it's ascii encoded binary, don't let any spaces in
128
            spec.StripWhitespace();
128
            spec.StripWhitespace();
129
        }
129
        }
130
130
131
        uri = do_CreateInstance(kSimpleURICID, &rv);
131
        uri = do_CreateInstance(kSimpleURICID, &rv);
132
        if (NS_FAILED(rv))
132
        if (NS_FAILED(rv))
133
            return rv;
133
            return rv;
134
134
        rv = uri->SetSpec(spec);
135
        rv = uri->SetSpec(spec);
136
        if (NS_FAILED(rv))
137
          return rv;
138
139
        rv = uri->SetRef(ref);
135
    }
140
    }
136
141
137
    if (NS_FAILED(rv))
142
    if (NS_FAILED(rv))
138
        return rv;
143
        return rv;
139
144
140
    uri.forget(result);
145
    uri.forget(result);
141
    return rv;
146
    return rv;
142
}
147
}
 Lines 166-182   nsDataHandler::AllowPort(PRInt32 port, c Link Here 
166
    return NS_OK;
171
    return NS_OK;
167
}
172
}
168
173
169
nsresult
174
nsresult
170
nsDataHandler::ParseURI(nsCString& spec,
175
nsDataHandler::ParseURI(nsCString& spec,
171
                        nsCString& contentType,
176
                        nsCString& contentType,
172
                        nsCString& contentCharset,
177
                        nsCString& contentCharset,
173
                        PRBool&    isBase64,
178
                        PRBool&    isBase64,
174
                        nsCString& dataBuffer) {
179
                        nsCString& dataBuffer,
180
                        nsCString& hashRef) {
175
    isBase64 = PR_FALSE;
181
    isBase64 = PR_FALSE;
176
182
177
    // move past "data:"
183
    // move past "data:"
178
    char *buffer = (char *) PL_strcasestr(spec.BeginWriting(), "data:");
184
    char *buffer = (char *) PL_strcasestr(spec.BeginWriting(), "data:");
179
    if (!buffer) {
185
    if (!buffer) {
180
        // malformed uri
186
        // malformed uri
181
        return NS_ERROR_MALFORMED_URI;
187
        return NS_ERROR_MALFORMED_URI;
182
    }
188
    }
 Lines 225-236   nsDataHandler::ParseURI(nsCString& spec, Link Here 
225
231
226
    *comma = ',';
232
    *comma = ',';
227
    if (isBase64)
233
    if (isBase64)
228
        *base64 = ';';
234
        *base64 = ';';
229
235
230
    contentType.StripWhitespace();
236
    contentType.StripWhitespace();
231
    contentCharset.StripWhitespace();
237
    contentCharset.StripWhitespace();
232
238
233
    dataBuffer.Assign(comma + 1);
239
    // Split encoded data from terminal "#ref" (if present)
240
    char *data = comma + 1;
241
    char *hash = strchr(data, '#');
242
    PRUint32 dataLen;
243
    if (!hash) {
244
        dataBuffer.Assign(data);
245
        hashRef.Truncate();
246
    } else {
247
        dataBuffer.Assign(data, hash - data);
248
        hashRef.Assign(hash);
249
    }
234
250
235
    return NS_OK;
251
    return NS_OK;
236
}
252
}
(-)a/netwerk/protocol/data/nsDataHandler.h (-1 / +2 lines)
Line     Link Here 
 Lines 58-69   public: Link Here 
58
58
59
    // Parse a data: URI and return the individual parts
59
    // Parse a data: URI and return the individual parts
60
    // (the given spec will temporarily be modified but will be returned
60
    // (the given spec will temporarily be modified but will be returned
61
    //  to the original before returning)
61
    //  to the original before returning)
62
    static NS_HIDDEN_(nsresult) ParseURI(nsCString& spec,
62
    static NS_HIDDEN_(nsresult) ParseURI(nsCString& spec,
63
                                         nsCString& contentType,
63
                                         nsCString& contentType,
64
                                         nsCString& contentCharset,
64
                                         nsCString& contentCharset,
65
                                         PRBool&    isBase64,
65
                                         PRBool&    isBase64,
66
                                         nsCString& dataBuffer);
66
                                         nsCString& dataBuffer,
67
                                         nsCString& hashRef);
67
};
68
};
68
69
69
#endif /* nsDataHandler_h___ */
70
#endif /* nsDataHandler_h___ */
(-)a/netwerk/test/reftest/658949-1-ref.html (+1 lines)
Line     Link Here 
Line 0    Link Here 
1
<iframe src="data:text/html,ABC"></iframe>
(-)a/netwerk/test/reftest/658949-1.html (+1 lines)
Line     Link Here 
Line 0    Link Here 
1
<iframe src="data:text/html,ABC#myRef"></iframe>
(-)a/netwerk/test/reftest/reftest.list (-1 / +1 lines)
Line     Link Here 
 Lines 1-2    Link Here 
1
== bug565432-1.html bug565432-1-ref.html
1
== bug565432-1.html bug565432-1-ref.html
2
2
== 658949-1.html 658949-1-ref.html

Return to bug 658949