Skip to content

Commit aa3a6d2

Browse files
committed
Update to node 8.9.4.
1 parent 03824b8 commit aa3a6d2

17 files changed

Lines changed: 2756 additions & 646 deletions

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# string_decoder
22

3-
***Node-core v7.0.0 string_decoder for userland***
3+
***Node-core v8.9.4 string_decoder for userland***
44

55

66
[![NPM](https://nodei.co/npm/string_decoder.png?downloads=true&downloadRank=true)](https://nodei.co/npm/string_decoder/)
@@ -15,7 +15,7 @@ npm install --save string_decoder
1515

1616
This package is a mirror of the string_decoder implementation in Node-core.
1717

18-
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v7.8.0/docs/api/).
18+
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v8.9.4/docs/api/).
1919

2020
As of version 1.0.0 **string_decoder** uses semantic versioning.
2121

‎build/build.js‎

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const hyperquest = require('hyperquest')
1616
, nodeVersionRegexString = '\\d+\\.\\d+\\.\\d+'
1717
, usageVersionRegex = RegExp('^' + nodeVersionRegexString + '$')
1818
, readmeVersionRegex =
19-
RegExp('((?:Node-core )|(?:https\:\/\/nodejs\.org\/dist\/)v)' + nodeVersionRegexString, 'g')
19+
RegExp('((?:(?:Node-core )|(?:https\:\/\/nodejs\.org\/dist\/))v)' + nodeVersionRegexString, 'g')
2020

2121
, readmePath = path.join(__dirname, '..', 'README.md')
2222
, files = require('./files')
@@ -49,21 +49,37 @@ function processFile (inputLoc, out, replacements) {
4949
var arg2 = replacement[1]
5050
if (typeof arg2 === 'function')
5151
arg2 = arg2.bind(data)
52+
if (arg2 === undefined) {
53+
console.error('missing second arg for file', inputLoc, replacement)
54+
throw new Error('missing second arg in replacement')
55+
}
5256
data = data.replace(regexp, arg2)
5357
})
5458
if (inputLoc.slice(-3) === '.js') {
55-
const transformed = babel.transform(data, {
56-
plugins: [
57-
'transform-es2015-parameters',
58-
'transform-es2015-arrow-functions',
59-
'transform-es2015-block-scoping',
60-
'transform-es2015-template-literals',
61-
'transform-es2015-shorthand-properties',
62-
'transform-es2015-for-of',
63-
'transform-es2015-destructuring'
64-
]
65-
})
66-
data = transformed.code
59+
try {
60+
const transformed = babel.transform(data, {
61+
plugins: [
62+
'transform-es2015-parameters',
63+
'transform-es2015-arrow-functions',
64+
'transform-es2015-block-scoping',
65+
'transform-es2015-template-literals',
66+
'transform-es2015-shorthand-properties',
67+
'transform-es2015-for-of',
68+
['transform-es2015-classes', { loose: true }],
69+
'transform-es2015-destructuring',
70+
'transform-es2015-computed-properties',
71+
'transform-es2015-spread'
72+
]
73+
})
74+
data = transformed.code
75+
} catch (err) {
76+
fs.writeFile(out + '.errored.js', data, encoding, function () {
77+
console.log('Wrote errored', out)
78+
79+
throw err
80+
})
81+
return
82+
}
6783
}
6884
fs.writeFile(out, data, encoding, function (err) {
6985
if (err) throw err
@@ -112,7 +128,6 @@ pump(
112128
throw err
113129
}
114130

115-
116131
//--------------------------------------------------------------------
117132
// Grab & process files in ../lib/
118133

@@ -137,15 +152,23 @@ pump(
137152
//--------------------------------------------------------------------
138153
// Grab the nodejs/node test/common.js
139154

140-
processFile(
141-
testsrcurl.replace(/parallel\/$/, 'common.js')
142-
, path.join(testourroot, '../common.js')
143-
, testReplace['common.js']
144-
)
155+
glob(path.join(src, 'test/common/*'), function (err, list) {
156+
if (err) {
157+
throw err
158+
}
159+
160+
list.forEach(function (file) {
161+
file = path.basename(file)
162+
processFile(
163+
path.join(testsrcurl.replace(/parallel\/$/, 'common/'), file)
164+
, path.join(testourroot.replace('parallel', 'common'), file)
165+
, testReplace['common.js']
166+
)
167+
})
168+
})
145169

146170
//--------------------------------------------------------------------
147171
// Update Node version in README
148-
149172
processFile(readmePath, readmePath, [
150173
[readmeVersionRegex, "$1" + nodeVersion]
151174
])

‎build/package.json‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
{
2-
"name": "string_decoder-build",
2+
"name": "readable-stream-build",
33
"version": "0.0.0",
44
"description": "",
55
"main": "build.js",
66
"dependencies": {
7-
"babel-core": "^6.5.2",
7+
"babel-core": "^6.26.0",
88
"babel-plugin-transform-es2015-arrow-functions": "^6.5.2",
9-
"babel-plugin-transform-es2015-block-scoping": "^6.5.0",
9+
"babel-plugin-transform-es2015-block-scoping": "^6.26.0",
10+
"babel-plugin-transform-es2015-classes": "^6.24.1",
11+
"babel-plugin-transform-es2015-computed-properties": "^6.24.1",
1012
"babel-plugin-transform-es2015-destructuring": "^6.18.0",
1113
"babel-plugin-transform-es2015-for-of": "^6.8.0",
12-
"babel-plugin-transform-es2015-parameters": "^6.11.4",
13-
"babel-plugin-transform-es2015-shorthand-properties": "^6.8.0",
14+
"babel-plugin-transform-es2015-parameters": "^6.24.1",
15+
"babel-plugin-transform-es2015-shorthand-properties": "^6.24.1",
16+
"babel-plugin-transform-es2015-spread": "^6.22.0",
1417
"babel-plugin-transform-es2015-template-literals": "^6.8.0",
15-
"bl": "^1.2.0",
16-
"glob": "^7.1.1",
17-
"gunzip-maybe": "^1.4.0",
18-
"hyperquest": "^2.1.2",
19-
"pump": "^1.0.2",
20-
"rimraf": "^2.6.1",
21-
"tar-fs": "^1.15.1"
18+
"bl": "^1.2.1",
19+
"glob": "^7.1.2",
20+
"gunzip-maybe": "^1.4.1",
21+
"hyperquest": "^2.1.3",
22+
"pump": "^3.0.0",
23+
"rimraf": "^2.6.2",
24+
"tar-fs": "^1.16.0"
2225
}
2326
}

‎lib/string_decoder.js‎

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
1+
// Copyright Joyent, Inc. and other Node contributors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to permit
8+
// persons to whom the Software is furnished to do so, subject to the
9+
// following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
122
'use strict';
223

3-
var Buffer = require('safe-buffer').Buffer;
24+
var _require = require('buffer'),
25+
Buffer = _require.Buffer;
426

527
var isEncoding = Buffer.isEncoding || function (encoding) {
628
encoding = '' + encoding;
@@ -112,10 +134,10 @@ StringDecoder.prototype.fillLast = function (buf) {
112134
};
113135

114136
// Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
115-
// continuation byte.
137+
// continuation byte. If an invalid byte is detected, -2 is returned.
116138
function utf8CheckByte(byte) {
117139
if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
118-
return -1;
140+
return byte >> 6 === 0x02 ? -1 : -2;
119141
}
120142

121143
// Checks at most 3 bytes at the end of a Buffer in order to detect an
@@ -129,13 +151,13 @@ function utf8CheckIncomplete(self, buf, i) {
129151
if (nb > 0) self.lastNeed = nb - 1;
130152
return nb;
131153
}
132-
if (--j < i) return 0;
154+
if (--j < i || nb === -2) return 0;
133155
nb = utf8CheckByte(buf[j]);
134156
if (nb >= 0) {
135157
if (nb > 0) self.lastNeed = nb - 2;
136158
return nb;
137159
}
138-
if (--j < i) return 0;
160+
if (--j < i || nb === -2) return 0;
139161
nb = utf8CheckByte(buf[j]);
140162
if (nb >= 0) {
141163
if (nb > 0) {
@@ -149,25 +171,25 @@ function utf8CheckIncomplete(self, buf, i) {
149171
// Validates as many continuation bytes for a multi-byte UTF-8 character as
150172
// needed or are available. If we see a non-continuation byte where we expect
151173
// one, we "replace" the validated continuation bytes we've seen so far with
152-
// UTF-8 replacement characters ('\ufffd'), to match v8's UTF-8 decoding
174+
// a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
153175
// behavior. The continuation byte check is included three times in the case
154176
// where all of the continuation bytes for a character exist in the same buffer.
155177
// It is also done this way as a slight performance increase instead of using a
156178
// loop.
157179
function utf8CheckExtraBytes(self, buf, p) {
158180
if ((buf[0] & 0xC0) !== 0x80) {
159181
self.lastNeed = 0;
160-
return '\ufffd'.repeat(p);
182+
return '\ufffd';
161183
}
162184
if (self.lastNeed > 1 && buf.length > 1) {
163185
if ((buf[1] & 0xC0) !== 0x80) {
164186
self.lastNeed = 1;
165-
return '\ufffd'.repeat(p + 1);
187+
return '\ufffd';
166188
}
167189
if (self.lastNeed > 2 && buf.length > 2) {
168190
if ((buf[2] & 0xC0) !== 0x80) {
169191
self.lastNeed = 2;
170-
return '\ufffd'.repeat(p + 2);
192+
return '\ufffd';
171193
}
172194
}
173195
}
@@ -198,11 +220,11 @@ function utf8Text(buf, i) {
198220
return buf.toString('utf8', i, end);
199221
}
200222

201-
// For UTF-8, a replacement character for each buffered byte of a (partial)
202-
// character needs to be added to the output.
223+
// For UTF-8, a replacement character is added when ending on a partial
224+
// character.
203225
function utf8End(buf) {
204226
var r = buf && buf.length ? this.write(buf) : '';
205-
if (this.lastNeed) return r + '\ufffd'.repeat(this.lastTotal - this.lastNeed);
227+
if (this.lastNeed) return r + '\ufffd';
206228
return r;
207229
}
208230

0 commit comments

Comments
 (0)