Skip to content

Commit

Permalink
Merge pull request #75 from danielgindi/fix/string_as_array
Browse files Browse the repository at this point in the history
Corrected "TypeError: Cannot assign to read only property", closes #68
  • Loading branch information
aadsm committed Mar 14, 2022
2 parents 5a57c11 + 2b9b07d commit a1c0607
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/eucjpprober.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions src/mbcharsetprober.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/sjisprober.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/universaldetector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 ) {
Expand Down

0 comments on commit a1c0607

Please sign in to comment.