Avoid using the Fetch API, in GENERIC
builds, for unsupported protocols (issue 10587)
This commit is contained in:
parent
cbc07f985b
commit
f664e074c9
@ -490,5 +490,6 @@ export {
|
|||||||
StatTimer,
|
StatTimer,
|
||||||
DummyStatTimer,
|
DummyStatTimer,
|
||||||
isFetchSupported,
|
isFetchSupported,
|
||||||
|
isValidFetchUrl,
|
||||||
loadScript,
|
loadScript,
|
||||||
};
|
};
|
||||||
|
17
src/pdf.js
17
src/pdf.js
@ -37,14 +37,17 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
|||||||
pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => {
|
pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => {
|
||||||
return new PDFNodeStream(params);
|
return new PDFNodeStream(params);
|
||||||
});
|
});
|
||||||
} else if (pdfjsDisplayDisplayUtils.isFetchSupported()) {
|
|
||||||
let PDFFetchStream = require('./display/fetch_stream.js').PDFFetchStream;
|
|
||||||
pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => {
|
|
||||||
return new PDFFetchStream(params);
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
let PDFNetworkStream = require('./display/network.js').PDFNetworkStream;
|
let PDFNetworkStream = require('./display/network.js').PDFNetworkStream;
|
||||||
|
let PDFFetchStream;
|
||||||
|
if (pdfjsDisplayDisplayUtils.isFetchSupported()) {
|
||||||
|
PDFFetchStream = require('./display/fetch_stream.js').PDFFetchStream;
|
||||||
|
}
|
||||||
pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => {
|
pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => {
|
||||||
|
if (PDFFetchStream &&
|
||||||
|
pdfjsDisplayDisplayUtils.isValidFetchUrl(params.url)) {
|
||||||
|
return new PDFFetchStream(params);
|
||||||
|
}
|
||||||
return new PDFNetworkStream(params);
|
return new PDFNetworkStream(params);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -69,8 +72,8 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
|||||||
PDFFetchStream = require('./display/fetch_stream.js').PDFFetchStream;
|
PDFFetchStream = require('./display/fetch_stream.js').PDFFetchStream;
|
||||||
}
|
}
|
||||||
pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => {
|
pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => {
|
||||||
if (PDFFetchStream && /^https?:/i.test(params.url)) {
|
if (PDFFetchStream &&
|
||||||
// "fetch" is only supported for http(s), not file/ftp.
|
pdfjsDisplayDisplayUtils.isValidFetchUrl(params.url)) {
|
||||||
return new PDFFetchStream(params);
|
return new PDFFetchStream(params);
|
||||||
}
|
}
|
||||||
return new PDFNetworkStream(params);
|
return new PDFNetworkStream(params);
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DOMSVGFactory, getFilenameFromUrl
|
DOMSVGFactory, getFilenameFromUrl, isValidFetchUrl
|
||||||
} from '../../src/display/display_utils';
|
} from '../../src/display/display_utils';
|
||||||
import isNodeJS from '../../src/shared/is_node';
|
import isNodeJS from '../../src/shared/is_node';
|
||||||
|
|
||||||
@ -94,4 +94,28 @@ describe('display_utils', function() {
|
|||||||
expect(result).toEqual(expected);
|
expect(result).toEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isValidFetchUrl', function() {
|
||||||
|
it('handles invalid Fetch URLs', function() {
|
||||||
|
expect(isValidFetchUrl(null)).toEqual(false);
|
||||||
|
expect(isValidFetchUrl(100)).toEqual(false);
|
||||||
|
expect(isValidFetchUrl('foo')).toEqual(false);
|
||||||
|
expect(isValidFetchUrl('/foo', 100)).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles relative Fetch URLs', function() {
|
||||||
|
expect(isValidFetchUrl('/foo', 'file://www.example.com')).toEqual(false);
|
||||||
|
expect(isValidFetchUrl('/foo', 'http://www.example.com')).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles unsupported Fetch protocols', function() {
|
||||||
|
expect(isValidFetchUrl('file://www.example.com')).toEqual(false);
|
||||||
|
expect(isValidFetchUrl('ftp://www.example.com')).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles supported Fetch protocols', function() {
|
||||||
|
expect(isValidFetchUrl('http://www.example.com')).toEqual(true);
|
||||||
|
expect(isValidFetchUrl('https://www.example.com')).toEqual(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user