8000 Honor the `size` option after following a redirect and revert data ur… · node-fetch/node-fetch@2358a6c · GitHub
[go: up one dir, main page]

Skip to content

Commit 2358a6c

Browse files
xxczakiRichienb
andauthored
Honor the size option after following a redirect and revert data uri support
Co-authored-by: Richie Bendall <richiebendall@gmail.com>
1 parent 8c197f8 commit 2358a6c

File tree

3 files changed

+8
-37
lines changed

3 files changed

+8
-37
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ Changelog
55

66
# 2.x release
77

8+
## v2.6.1
9+
10+
**This is an important security release. It is strongly recommended to update as soon as possible.**
11+
12+
- Fix: honor the `size` option after following a redirect.
13+
814
## v2.6.0
915

1016
- Enhance: `options.agent`, it now accepts a function that returns custom http(s).Agent instance based on current URL, see readme for more information.

src/index.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,6 @@ export default function fetch(url, opts) {
3838
throw new Error('native promise missing, set fetch.Promise to your favorite alternative');
3939
}
4040

41-
if (/^data:/.test(url)) {
42-
const request = new Request(url, opts);
43-
try {
44-
const data = Buffer.from(url.split(',')[1], 'base64')
45-
const res = new Response(data.body, { headers: { 'Content-Type': data.mimeType || url.match(/^data:(.+);base64,.*$/)[1] } });
46-
return fetch.Promise.resolve(res);
47-
} catch (err) {
48-
return fetch.Promise.reject(new FetchError(`[${request.method}] ${request.url} invalid URL, ${err.message}`, 'system', err));
49-
}
50-
}
51-
5241
Body.Promise = fetch.Promise;
5342

5443
// wrap http.request into fetch
@@ -164,7 +153,8 @@ export default function fetch(url, opts) {
164153
method: request.method,
165154
body: request.body,
166155
signal: request.signal,
167-
timeout: request.timeout
156+
timeout: request.timeout,
157+
size: request.size
168158
};
169159

170160
// HTTP-redirect fetch step 9

test/test.js

-25
Original file line numberDiff line numberDiff line change
@@ -2844,29 +2844,4 @@ describe('external encoding', () => {
28442844
});
28452845
});
28462846
});
2847-
2848-
describe('data uri', function() {
2849-
const dataUrl = 'data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=';
2850-
2851-
const invalidDataUrl = 'data:@@@@';
2852-
2853-
it('should accept data uri', function() {
2854-
return fetch(dataUrl).then(r => {
2855-
console.assert(r.status == 200);
2856-
console.assert(r.headers.get('Content-Type') == 'image/gif');
2857-
2858-
return r.buffer().then(b => {
2859-
console.assert(b instanceof Buffer);
2860-
});
2861-
});
2862-
});
2863-
2864-
it('should reject invalid data uri', function() {
2865-
return fetch(invalidDataUrl)
2866-
.catch(e => {
2867-
console.assert(e);
2868-
console.assert(e.message.includes('invalid URL'));
2869-
});
2870-
});
2871-
});
28722847
});

0 commit comments

Comments
 (0)
0