Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot assign to read only property '1' of string '' #68

Closed
maiermic opened this issue Jul 28, 2021 · 14 comments
Closed

TypeError: Cannot assign to read only property '1' of string '' #68

maiermic opened this issue Jul 28, 2021 · 14 comments

Comments

@maiermic
Copy link

maiermic commented Jul 28, 2021

The error

ERROR TypeError: Cannot assign to read only property '1' of string '��'
    at SJISProber.feed (sjisprober.js:73)
    at MBCSGroupProber.CharSetGroupProber.feed (charsetgroupprober.js:69)
    at UniversalDetector.feed (universaldetector.js:156)
    at runUniversalDetector (index.js:52)
    at Object.push.rVdK.exports.detect (index.js:34)
    at FileReader.fileReader.onload (app.component.ts:21)
    at ZoneDelegate.invoke (zone-evergreen.js:364)
    at Object.onInvoke (core.js:28494)
    at ZoneDelegate.invoke (zone-evergreen.js:363)
    at Zone.runGuarded (zone-evergreen.js:133)

is thrown in

this._mLastChar[1] = aBuf[0];

in my Angular 11 project, when I select cp1252.txt in the input of my AppComponent

app.component.ts

import { Component } from '@angular/core';
import * as jschardet from 'jschardet';

@Component({
  selector: 'app-root',
  template: `
      <input type="file" id="file" (change)="decode($event)">
  `
})
export class AppComponent {
  decode(e: any) {
    const file = e.target.files[0];
    console.log(typeof file);
    const fileReader = new FileReader();
    fileReader.onload = function() {
      const array = new Uint8Array(fileReader.result as ArrayBuffer);
      let string = "";
      for (let i = 0; i < array.length; ++i) {
        string += String.fromCharCode(array[i]);
      }
      console.log(jschardet.detect(string));
    };
    fileReader.readAsArrayBuffer(file);
  }
}

I only have this issue in a larger Angular project. I tried to reproduce it in a new Angular project as minimal example, but the TypeError is not thrown in this project. I suspect that some (build) configuration is different between the two projects, but I can't think of what that might be. Do you have any idea?

Besides, what should

this._mLastChar[1] = aBuf[0];

actually do? this._mLastChar is a string. They are immutable in JavaScript, aren't they?


https://stackoverflow.com/q/68568242/1065654

@maiermic
Copy link
Author

maiermic commented Jul 28, 2021

The error only occurs in strict mode, but I use the same tsconfig.json and tsconfig.app.json in both projects. Even angular.json, package.json and package-lock.json are the same. Why is my large project running jschardet in strict mode, but my other Angular app not? 😕

@maiermic
Copy link
Author

I discovered a workaround. It is working if I use a dynamic import

const jschardet = await import('jschardet');
console.log(jschardet.detect(string));

@danielgindi
Copy link
Contributor

These are immutable. These lines do nothing. I have no idea what the author intended to do there - it may be some kind of translation from C or Java. In which case, string slice and concatenation should occur.

@aadsm
Copy link
Owner

aadsm commented Mar 14, 2022

These are immutable. These lines do nothing. I have no idea what the author intended to do there - it may be some kind of translation from C or Java. In which case, string slice and concatenation should occur.

Yap, it's a translation from python, and at the time I had 0 knowledge on python 😅.

@aadsm aadsm closed this as completed in 2b9b07d Mar 14, 2022
aadsm added a commit that referenced this issue Mar 14, 2022
Corrected "TypeError: Cannot assign to read only property", closes #68
@maiermic
Copy link
Author

@aadsm @danielgindi Thank you very much ❤️

@luastoned
Copy link

When will a version with this fix be published?

@maiermic
Copy link
Author

@aadsm Has this fix been published in the meantime? The workaround doesn't seem to work anymore.

@danielgindi
Copy link
Contributor

@aadsm Has this fix been published in the meantime? The workaround doesn't seem to work anymore.

It was merged but a new version was not released

@maiermic
Copy link
Author

@danielgindi Thanks, that's what I was afraid of. Are you able to build the project (see #81)? It would be possible to install the library from a Github repository (e.g. fork), but the official repository still contains the old build files (last release 3.0.0):

npm install --save github:aadsm/jschardet#master

@YLeventhal
Copy link

It was merged but a new version was not released

@danielgindi any updates regarding when a new version will be released ?

@SkiiNox
Copy link

SkiiNox commented Aug 7, 2023

I also have this issue and a new release would be great

@GreatAuk
Copy link

+1

@rabih-elzahr
Copy link

I have the same issue I see the fix is merged but not released. Are you planning to release a new version soon? if not is there any work arounds?

@aadsm
Copy link
Owner

aadsm commented Feb 22, 2024

I have the same issue I see the fix is merged but not released. Are you planning to release a new version soon? if not is there any work arounds?

I'm working on this right now. I'm automating the publishing so it's automatic for new commits.

github-actions bot pushed a commit that referenced this issue Feb 29, 2024
Changes since 3.1.6:
2698f33 Version 3.1.6 (patch)\nd500c29 Version 3.1.5 (patch)\n1d1ff49 Version 3.1.4 (patch)\n3a2d31b Version 3.1.3 (patch)\n08d9559 Version 3.1.2 (patch)\n2f9d07c Version 3.1.1 (patch)\nef7d0da Version 3.1.0 (minor) \\n \\n Changes since git tag --list v* --sort=-taggerdate | head -1: \\n\n1e8ceb3 3.0.1\n4d45864 Updated browserify and jest versions\n56e10ee Cosmetic changes to the way the percentage is shown in show-size-changes.sh\n7010531 Add script to determine size changes in the distributed files\n120c0e7 npm audit --fix\na1c0607 Merge pull request #75 from danielgindi/fix/string_as_array\n2b9b07d Corrected \"TypeError: Cannot assign to read only property\", closes #68\n5a57c11 Convert the encodings tests to jest\n08e6c81 Add initial set of jest tests\n7897929 Check if given encodings exist against the denormalized list of supported encodings\naf66fa6 Add typescript support to detectEncodings\n9b49243 Add detectEncondings option\ne5945e2 Merge branch master of https://github.com/aadsm/jschardet\n71bcf43 npm audit fix\n094cb6f Merge pull request #71 from bpasero/patch-1\nc089b44 Add `detectAll` to index.d.ts\n0ae9a3c Update package-lock.json\nf71723b Add .npmignore to exclude tests
github-actions bot pushed a commit that referenced this issue Feb 29, 2024
Changes since 3.1.6:
296ee53 3.2.0
2698f33 Version 3.1.6 (patch)
d500c29 Version 3.1.5 (patch)
1d1ff49 Version 3.1.4 (patch)
3a2d31b Version 3.1.3 (patch)
08d9559 Version 3.1.2 (patch)
2f9d07c Version 3.1.1 (patch)
ef7d0da Version 3.1.0 (minor) \n \n Changes since git tag --list 'v*' --sort=-taggerdate | head -1: \n
1e8ceb3 3.0.1
4d45864 Updated browserify and jest versions
56e10ee Cosmetic changes to the way the percentage is shown in show-size-changes.sh
7010531 Add script to determine size changes in the distributed files
120c0e7 npm audit --fix
a1c0607 Merge pull request #75 from danielgindi/fix/string_as_array
2b9b07d Corrected "TypeError: Cannot assign to read only property", closes #68
5a57c11 Convert the encodings tests to jest
08e6c81 Add initial set of jest tests
7897929 Check if given encodings exist against the denormalized list of supported encodings
af66fa6 Add typescript support to detectEncodings
9b49243 Add detectEncondings option
e5945e2 Merge branch 'master' of https://github.com/aadsm/jschardet
71bcf43 npm audit fix
094cb6f Merge pull request #71 from bpasero/patch-1
c089b44 Add `detectAll` to index.d.ts
0ae9a3c Update package-lock.json
f71723b Add .npmignore to exclude tests
github-actions bot pushed a commit that referenced this issue Feb 29, 2024
Changes since 3.1.6:
2698f33 Version 3.1.6 (patch)
d500c29 Version 3.1.5 (patch)
1d1ff49 Version 3.1.4 (patch)
3a2d31b Version 3.1.3 (patch)
08d9559 Version 3.1.2 (patch)
2f9d07c Version 3.1.1 (patch)
ef7d0da Version 3.1.0 (minor) \n \n Changes since git tag --list 'v*' --sort=-taggerdate | head -1: \n
1e8ceb3 3.0.1
4d45864 Updated browserify and jest versions
56e10ee Cosmetic changes to the way the percentage is shown in show-size-changes.sh
7010531 Add script to determine size changes in the distributed files
120c0e7 npm audit --fix
a1c0607 Merge pull request #75 from danielgindi/fix/string_as_array
2b9b07d Corrected "TypeError: Cannot assign to read only property", closes #68
5a57c11 Convert the encodings tests to jest
08e6c81 Add initial set of jest tests
7897929 Check if given encodings exist against the denormalized list of supported encodings
af66fa6 Add typescript support to detectEncodings
9b49243 Add detectEncondings option
e5945e2 Merge branch 'master' of https://github.com/aadsm/jschardet
71bcf43 npm audit fix
094cb6f Merge pull request #71 from bpasero/patch-1
c089b44 Add `detectAll` to index.d.ts
0ae9a3c Update package-lock.json
f71723b Add .npmignore to exclude tests
aadsm added a commit that referenced this issue Mar 19, 2024
Changes since 3.0.0:
f3de69b Updated bundles
25f107a Updated github workflow files
4d45864 Updated browserify and jest versions
56e10ee Cosmetic changes to the way the percentage is shown in show-size-changes.sh
7010531 Add script to determine size changes in the distributed files
120c0e7 npm audit --fix
a1c0607 Merge pull request #75 from danielgindi/fix/string_as_array
2b9b07d Corrected "TypeError: Cannot assign to read only property", closes #68
5a57c11 Convert the encodings tests to jest
08e6c81 Add initial set of jest tests
7897929 Check if given encodings exist against the denormalized list of supported encodings
af66fa6 Add typescript support to detectEncodings
9b49243 Add detectEncondings option
e5945e2 Merge branch 'master' of https://github.com/aadsm/jschardet
71bcf43 npm audit fix
094cb6f Merge pull request #71 from bpasero/patch-1
c089b44 Add `detectAll` to index.d.ts
0ae9a3c Update package-lock.json
f71723b Add .npmignore to exclude tests

Bundle size changes since v3.0.0:
* dist/jschardet.js +3135 (465888 -> 469023)
* dist/jschardet.min.js +3460 +0.01% (335803 -> 339263)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants