From 2b9b07dbcbe07a1876adfc76ff06bfbd5305bc2b Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Tue, 1 Feb 2022 19:53:38 +0200 Subject: [PATCH] Corrected "TypeError: Cannot assign to read only property", closes #68 --- src/eucjpprober.js | 5 +++-- src/mbcharsetprober.js | 8 +++----- src/sjisprober.js | 4 ++-- src/universaldetector.js | 6 +++--- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/eucjpprober.js b/src/eucjpprober.js index e978878..45cf4c2 100644 --- a/src/eucjpprober.js +++ b/src/eucjpprober.js @@ -71,8 +71,9 @@ function EUCJPProber() { var charLen = this._mCodingSM.getCurrentCharLen(); if( i == 0 ) { this._mLastChar[1] = aBuf[0]; - this._mContextAnalyzer.feed(this._mLastChar, charLen); - this._mDistributionAnalyzer.feed(this._mLastChar, charLen); + var lastCharStr = this._mLastChar.join(''); + this._mContextAnalyzer.feed(lastCharStr, charLen); + this._mDistributionAnalyzer.feed(lastCharStr, charLen); } else { this._mContextAnalyzer.feed(aBuf.slice(i-1,i+1), charLen); this._mDistributionAnalyzer.feed(aBuf.slice(i-1,i+1), charLen); diff --git a/src/mbcharsetprober.js b/src/mbcharsetprober.js index c03719b..7c2ec7a 100644 --- a/src/mbcharsetprober.js +++ b/src/mbcharsetprober.js @@ -39,8 +39,7 @@ var logger = require('./logger'); function init() { self._mDistributionAnalyzer = null; self._mCodingSM = null; - //self._mLastChar = ["\x00", "\x00"]; - self._mLastChar = "\x00\x00"; + self._mLastChar = ["\x00", "\x00"]; } this.reset = function() { @@ -51,8 +50,7 @@ var logger = require('./logger'); if( this._mDistributionAnalyzer ) { this._mDistributionAnalyzer.reset(); } - //this._mLastChar = ["\x00", "\x00"]; - this._mLastChar = "\x00\x00"; + this._mLastChar = ["\x00", "\x00"]; } this.getCharsetName = function() { @@ -73,7 +71,7 @@ var logger = require('./logger'); var charLen = this._mCodingSM.getCurrentCharLen(); if( i == 0 ) { this._mLastChar[1] = aBuf[0]; - this._mDistributionAnalyzer.feed(this._mLastChar, charLen); + this._mDistributionAnalyzer.feed(this._mLastChar.join(''), charLen); } else { this._mDistributionAnalyzer.feed(aBuf.slice(i-1,i+1), charLen); } diff --git a/src/sjisprober.js b/src/sjisprober.js index 3160a66..4248fa2 100644 --- a/src/sjisprober.js +++ b/src/sjisprober.js @@ -71,8 +71,8 @@ function SJISProber() { var charLen = this._mCodingSM.getCurrentCharLen(); if( i == 0 ) { this._mLastChar[1] = aBuf[0]; - this._mContextAnalyzer.feed(this._mLastChar.slice(2 - charLen), charLen); - this._mDistributionAnalyzer.feed(this._mLastChar, charLen); + this._mContextAnalyzer.feed(this._mLastChar.slice(2 - charLen).join(''), charLen); + this._mDistributionAnalyzer.feed(this._mLastChar.join(''), charLen); } else { this._mContextAnalyzer.feed(aBuf.slice(i + 1 - charLen, i + 3 - charLen), charLen); this._mDistributionAnalyzer.feed(aBuf.slice(i - 1, i + 1), charLen); diff --git a/src/universaldetector.js b/src/universaldetector.js index c335591..8f51d22 100644 --- a/src/universaldetector.js +++ b/src/universaldetector.js @@ -108,7 +108,7 @@ function UniversalDetector(options) { this._mStart = true; this._mGotData = false; this._mInputState = _state.pureAscii; - this._mLastChar = ""; + this._mLastChar = []; this._mBOM = ""; if( this._mEscCharsetProber ) { this._mEscCharsetProber.reset(); @@ -169,12 +169,12 @@ function UniversalDetector(options) { if( this._mInputState == _state.pureAscii ) { if( this._highBitDetector.test(aBuf) ) { this._mInputState = _state.highbyte; - } else if( this._escDetector.test(this._mLastChar + aBuf) ) { + } else if( this._escDetector.test(this._mLastChar.join('') + aBuf) ) { this._mInputState = _state.escAscii; } } - this._mLastChar = aBuf.slice(-1); + this._mLastChar = aBuf.slice(-1).split(''); if( this._mInputState == _state.escAscii ) { if( !this._mEscCharsetProber ) {