Skip to content

Commit 90e2a66

Browse files
Fixed a buffer bug
1 parent e1e3279 commit 90e2a66

5 files changed

Lines changed: 149 additions & 82 deletions

File tree

dist/ref-parser.js

Lines changed: 107 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ function setValue(pointer, token, value) {
876876
module.exports = typeof(Promise) === 'function' ? Promise : require('es6-promise').Promise;
877877

878878
},{"es6-promise":18}],8:[function(require,module,exports){
879-
(function (process){
879+
(function (process,Buffer){
880880
'use strict';
881881

882882
var fs = require('fs'),
@@ -1077,8 +1077,12 @@ function download(protocol, u, options) {
10771077
var body;
10781078

10791079
res.on('data', function(data) {
1080-
// Data can be a string or a buffer
1081-
body = body ? body.concat(data) : data;
1080+
if (body) {
1081+
body = Buffer.concat([new Buffer(body), new Buffer(data)]);
1082+
}
1083+
else {
1084+
body = data;
1085+
}
10821086
});
10831087

10841088
res.on('end', function() {
@@ -1100,9 +1104,9 @@ function download(protocol, u, options) {
11001104
});
11011105
}
11021106

1103-
}).call(this,require('_process'))
1107+
}).call(this,require('_process'),require("buffer").Buffer)
11041108

1105-
},{"./parse":5,"./promise":7,"./ref":9,"./util":12,"_process":61,"fs":51,"http":80,"https":58,"ono":50,"url":90}],9:[function(require,module,exports){
1109+
},{"./parse":5,"./promise":7,"./ref":9,"./util":12,"_process":61,"buffer":53,"fs":51,"http":80,"https":58,"ono":50,"url":90}],9:[function(require,module,exports){
11061110
'use strict';
11071111

11081112
module.exports = $Ref;
@@ -12631,12 +12635,14 @@ function errorToJSON() {
1263112635
},{}],52:[function(require,module,exports){
1263212636
arguments[4][51][0].apply(exports,arguments)
1263312637
},{"dup":51}],53:[function(require,module,exports){
12638+
(function (global){
1263412639
/*!
1263512640
* The buffer module from node.js, for the browser.
1263612641
*
1263712642
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
1263812643
* @license MIT
1263912644
*/
12645+
/* eslint-disable no-proto */
1264012646

1264112647
var base64 = require('base64-js')
1264212648
var ieee754 = require('ieee754')
@@ -12676,20 +12682,22 @@ var rootParent = {}
1267612682
* We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
1267712683
* get the Object implementation, which is slower but behaves correctly.
1267812684
*/
12679-
Buffer.TYPED_ARRAY_SUPPORT = (function () {
12680-
function Bar () {}
12681-
try {
12682-
var arr = new Uint8Array(1)
12683-
arr.foo = function () { return 42 }
12684-
arr.constructor = Bar
12685-
return arr.foo() === 42 && // typed array instances can be augmented
12686-
arr.constructor === Bar && // constructor can be set
12687-
typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
12688-
arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
12689-
} catch (e) {
12690-
return false
12691-
}
12692-
})()
12685+
Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
12686+
? global.TYPED_ARRAY_SUPPORT
12687+
: (function () {
12688+
function Bar () {}
12689+
try {
12690+
var arr = new Uint8Array(1)
12691+
arr.foo = function () { return 42 }
12692+
arr.constructor = Bar
12693+
return arr.foo() === 42 && // typed array instances can be augmented
12694+
arr.constructor === Bar && // constructor can be set
12695+
typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
12696+
arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
12697+
} catch (e) {
12698+
return false
12699+
}
12700+
})()
1269312701

1269412702
function kMaxLength () {
1269512703
return Buffer.TYPED_ARRAY_SUPPORT
@@ -12845,10 +12853,16 @@ function fromJsonObject (that, object) {
1284512853
return that
1284612854
}
1284712855

12856+
if (Buffer.TYPED_ARRAY_SUPPORT) {
12857+
Buffer.prototype.__proto__ = Uint8Array.prototype
12858+
Buffer.__proto__ = Uint8Array
12859+
}
12860+
1284812861
function allocate (that, length) {
1284912862
if (Buffer.TYPED_ARRAY_SUPPORT) {
1285012863
// Return an augmented `Uint8Array` instance, for best performance
1285112864
that = Buffer._augment(new Uint8Array(length))
12865+
that.__proto__ = Buffer.prototype
1285212866
} else {
1285312867
// Fallback: Return an object instance of the Buffer class
1285412868
that.length = length
@@ -14165,6 +14179,8 @@ function blitBuffer (src, dst, offset, length) {
1416514179
return i
1416614180
}
1416714181

14182+
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
14183+
1416814184
},{"base64-js":54,"ieee754":55,"is-array":56}],54:[function(require,module,exports){
1416914185
var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
1417014186

@@ -17731,19 +17747,19 @@ http.request = function (opts, cb) {
1773117747
else
1773217748
opts = extend(opts)
1773317749

17734-
// Split opts.host into its components
17735-
var hostHostname = opts.host ? opts.host.split(':')[0] : null
17736-
var hostPort = opts.host ? parseInt(opts.host.split(':')[1], 10) : null
17750+
var protocol = opts.protocol || ''
17751+
var host = opts.hostname || opts.host
17752+
var port = opts.port
17753+
var path = opts.path || '/'
17754+
17755+
// Necessary for IPv6 addresses
17756+
if (host && host.indexOf(':') !== -1)
17757+
host = '[' + host + ']'
1773717758

17738-
opts.method = opts.method || 'GET'
17759+
// This may be a relative url. The browser should always be able to interpret it correctly.
17760+
opts.url = (host ? (protocol + '//' + host) : '') + (port ? ':' + port : '') + path
17761+
opts.method = (opts.method || 'GET').toUpperCase()
1773917762
opts.headers = opts.headers || {}
17740-
opts.path = opts.path || '/'
17741-
opts.protocol = opts.protocol || window.location.protocol
17742-
// If the hostname is provided, use the default port for the protocol. If
17743-
// the url is instead relative, use window.location.port
17744-
var defaultPort = (opts.hostname || hostHostname) ? (opts.protocol === 'https:' ? 443 : 80) : window.location.port
17745-
opts.hostname = opts.hostname || hostHostname || window.location.hostname
17746-
opts.port = opts.port || hostPort || defaultPort
1774717763

1774817764
// Also valid opts.auth, opts.mode
1774917765

@@ -17793,16 +17809,19 @@ http.METHODS = [
1779317809
'UNSUBSCRIBE'
1779417810
]
1779517811
},{"./lib/request":82,"builtin-status-codes":84,"url":90,"xtend":93}],81:[function(require,module,exports){
17796-
exports.fetch = isFunction(window.fetch) && isFunction(window.ReadableByteStream)
17812+
(function (global){
17813+
exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableByteStream)
1779717814

1779817815
exports.blobConstructor = false
1779917816
try {
1780017817
new Blob([new ArrayBuffer(1)])
1780117818
exports.blobConstructor = true
1780217819
} catch (e) {}
1780317820

17804-
var xhr = new window.XMLHttpRequest()
17805-
xhr.open('GET', '/')
17821+
var xhr = new global.XMLHttpRequest()
17822+
// If location.host is empty, e.g. if this page/worker was loaded
17823+
// from a Blob, then use example.com to avoid an error
17824+
xhr.open('GET', global.location.host ? '/' : 'https://example.com')
1780617825

1780717826
function checkTypeSupport (type) {
1780817827
try {
@@ -17812,10 +17831,10 @@ function checkTypeSupport (type) {
1781217831
return false
1781317832
}
1781417833

17815-
// For some strange reason, Safari 7.0 reports typeof window.ArrayBuffer === 'object'.
17834+
// For some strange reason, Safari 7.0 reports typeof global.ArrayBuffer === 'object'.
1781617835
// Safari 7.1 appears to have fixed this bug.
17817-
var haveArrayBuffer = typeof window.ArrayBuffer !== 'undefined'
17818-
var haveSlice = haveArrayBuffer && isFunction(window.ArrayBuffer.prototype.slice)
17836+
var haveArrayBuffer = typeof global.ArrayBuffer !== 'undefined'
17837+
var haveSlice = haveArrayBuffer && isFunction(global.ArrayBuffer.prototype.slice)
1781917838

1782017839
exports.arraybuffer = haveArrayBuffer && checkTypeSupport('arraybuffer')
1782117840
// These next two tests unavoidably show warnings in Chrome. Since fetch will always
@@ -17824,16 +17843,18 @@ exports.msstream = !exports.fetch && haveSlice && checkTypeSupport('ms-stream')
1782417843
exports.mozchunkedarraybuffer = !exports.fetch && haveArrayBuffer &&
1782517844
checkTypeSupport('moz-chunked-arraybuffer')
1782617845
exports.overrideMimeType = isFunction(xhr.overrideMimeType)
17827-
exports.vbArray = isFunction(window.VBArray)
17846+
exports.vbArray = isFunction(global.VBArray)
1782817847

1782917848
function isFunction (value) {
1783017849
return typeof value === 'function'
1783117850
}
1783217851

1783317852
xhr = null // Help gc
1783417853

17854+
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
17855+
1783517856
},{}],82:[function(require,module,exports){
17836-
(function (process,Buffer){
17857+
(function (process,global,Buffer){
1783717858
// var Base64 = require('Base64')
1783817859
var capability = require('./capability')
1783917860
var foreach = require('foreach')
@@ -17867,7 +17888,6 @@ var ClientRequest = module.exports = function (opts) {
1786717888
stream.Writable.call(self)
1786817889

1786917890
self._opts = opts
17870-
self._url = opts.protocol + '//' + opts.hostname + ':' + opts.port + opts.path
1787117891
self._body = []
1787217892
self._headers = {}
1787317893
if (opts.auth)
@@ -17935,7 +17955,7 @@ ClientRequest.prototype._onFinish = function () {
1793517955
var body
1793617956
if (opts.method === 'POST' || opts.method === 'PUT') {
1793717957
if (capability.blobConstructor) {
17938-
body = new window.Blob(self._body.map(function (buffer) {
17958+
body = new global.Blob(self._body.map(function (buffer) {
1793917959
return buffer.toArrayBuffer()
1794017960
}), {
1794117961
type: (headersObj['content-type'] || {}).value || ''
@@ -17951,7 +17971,7 @@ ClientRequest.prototype._onFinish = function () {
1795117971
return [headersObj[name].name, headersObj[name].value]
1795217972
})
1795317973

17954-
window.fetch(self._url, {
17974+
global.fetch(self._opts.url, {
1795517975
method: self._opts.method,
1795617976
headers: headers,
1795717977
body: body,
@@ -17964,9 +17984,9 @@ ClientRequest.prototype._onFinish = function () {
1796417984
self.emit('error', reason)
1796517985
})
1796617986
} else {
17967-
var xhr = self._xhr = new window.XMLHttpRequest()
17987+
var xhr = self._xhr = new global.XMLHttpRequest()
1796817988
try {
17969-
xhr.open(self._opts.method, self._url, true)
17989+
xhr.open(self._opts.method, self._opts.url, true)
1797017990
} catch (err) {
1797117991
process.nextTick(function () {
1797217992
self.emit('error', err)
@@ -18114,10 +18134,10 @@ var unsafeHeaders = [
1811418134
'via'
1811518135
]
1811618136

18117-
}).call(this,require('_process'),require("buffer").Buffer)
18137+
}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer)
1811818138

1811918139
},{"./capability":81,"./response":83,"_process":61,"buffer":53,"foreach":85,"indexof":86,"inherits":59,"object-keys":87,"stream":79}],83:[function(require,module,exports){
18120-
(function (process,Buffer){
18140+
(function (process,global,Buffer){
1812118141
var capability = require('./capability')
1812218142
var foreach = require('foreach')
1812318143
var inherits = require('inherits')
@@ -18227,7 +18247,7 @@ IncomingMessage.prototype._onXHRProgress = function () {
1822718247
break
1822818248
try {
1822918249
// This fails in IE8
18230-
response = new window.VBArray(xhr.responseBody).toArray()
18250+
response = new global.VBArray(xhr.responseBody).toArray()
1823118251
} catch (e) {}
1823218252
if (response !== null) {
1823318253
self.push(new Buffer(response))
@@ -18271,7 +18291,7 @@ IncomingMessage.prototype._onXHRProgress = function () {
1827118291
response = xhr.response
1827218292
if (xhr.readyState !== rStates.LOADING)
1827318293
break
18274-
var reader = new window.MSStreamReader()
18294+
var reader = new global.MSStreamReader()
1827518295
reader.onprogress = function () {
1827618296
if (reader.result.byteLength > self._pos) {
1827718297
self.push(new Buffer(new Uint8Array(reader.result.slice(self._pos))))
@@ -18292,7 +18312,7 @@ IncomingMessage.prototype._onXHRProgress = function () {
1829218312
}
1829318313
}
1829418314

18295-
}).call(this,require('_process'),require("buffer").Buffer)
18315+
}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer)
1829618316

1829718317
},{"./capability":81,"_process":61,"buffer":53,"foreach":85,"inherits":59,"stream":79}],84:[function(require,module,exports){
1829818318
module.exports = {
@@ -18409,6 +18429,44 @@ var dontEnums = [
1840918429
'propertyIsEnumerable',
1841018430
'constructor'
1841118431
];
18432+
var equalsConstructorPrototype = function (o) {
18433+
var ctor = o.constructor;
18434+
return ctor && ctor.prototype === o;
18435+
};
18436+
var blacklistedKeys = {
18437+
$window: true,
18438+
$console: true,
18439+
$parent: true,
18440+
$self: true,
18441+
$frames: true,
18442+
$webkitIndexedDB: true,
18443+
$webkitStorageInfo: true
18444+
};
18445+
var hasAutomationEqualityBug = (function () {
18446+
/* global window */
18447+
if (typeof window === 'undefined') { return false; }
18448+
for (var k in window) {
18449+
if (!blacklistedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
18450+
try {
18451+
equalsConstructorPrototype(window[k]);
18452+
} catch (e) {
18453+
return true;
18454+
}
18455+
}
18456+
}
18457+
return false;
18458+
}());
18459+
var equalsConstructorPrototypeIfNotBuggy = function (o) {
18460+
/* global window */
18461+
if (typeof window === 'undefined' && !hasAutomationEqualityBug) {
18462+
return equalsConstructorPrototype(o);
18463+
}
18464+
try {
18465+
return equalsConstructorPrototype(o);
18466+
} catch (e) {
18467+
return false;
18468+
}
18469+
};
1841218470

1841318471
var keysShim = function keys(object) {
1841418472
var isObject = object !== null && typeof object === 'object';
@@ -18441,8 +18499,7 @@ var keysShim = function keys(object) {
1844118499
}
1844218500

1844318501
if (hasDontEnumBug) {
18444-
var ctor = object.constructor;
18445-
var skipConstructor = ctor && ctor.prototype === object;
18502+
var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
1844618503

1844718504
for (var k = 0; k < dontEnums.length; ++k) {
1844818505
if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {

dist/ref-parser.js.map

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ref-parser.min.js

Lines changed: 20 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ref-parser.min.js.map

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/read.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,12 @@ function download(protocol, u, options) {
198198
var body;
199199

200200
res.on('data', function(data) {
201-
// Data can be a string or a buffer
202-
body = body ? body.concat(data) : data;
201+
if (body) {
202+
body = Buffer.concat([new Buffer(body), new Buffer(data)]);
203+
}
204+
else {
205+
body = data;
206+
}
203207
});
204208

205209
res.on('end', function() {

0 commit comments

Comments
 (0)