Skip to content

Commit 314c6b3

Browse files
committed
Don't allow invalid encodings in StringDecoder class
1 parent 77ed12f commit 314c6b3

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

lib/string_decoder.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@
1919
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

22+
function assertEncoding(encoding) {
23+
if (encoding && !Buffer.isEncoding(encoding)) {
24+
throw new Error('Unknown encoding: ' + encoding);
25+
}
26+
}
27+
2228
var StringDecoder = exports.StringDecoder = function(encoding) {
2329
this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
30+
assertEncoding(encoding);
2431
switch (this.encoding) {
2532
case 'utf8':
2633
// CESU-8 represents each of Surrogate Pair by 3-bytes

0 commit comments

Comments
 (0)