UTF-8 Character Support Issue: Error with Turkish Character
https://github.com/Anof-cyber/PyCript/blob/221b91e0b14cc2cba970c5668dbfcce791b4a8a6/pycript/gethelpers.py#L21-L26
gethelpers.py", line 26, in <genexpr>
return ''.join(chr(code) for code in byte_data2)
ValueError: chr() arg not in range(256)
Can you add UTF-8 character support? The character I tested is: 'İ', and it gave the error mentioned above.
can you share the output of your script? UFT-8 has already been tested and is working fine.
It could be an error in your script. Can you check if your script return the Byte Array format for the output. You can check logs in the extension to verify it.
const fs = require('fs');
const path = require('path');
const {
program
} = require('commander');
const {
Buffer
} = require('buffer');
try {
program
.option('-d, --data <file_path>', 'Path to JSON file containing base64 encoded + encrypted data');
program.parse(process.argv);
const options = program.opts();
const filePath = options.data;
const absoluteFilePath = path.resolve(filePath);
var data = fs.readFileSync(absoluteFilePath, 'utf8');
const bodyEndMarker = '\n--BODY_END--\n';
const [byteArrayStr, headersRaw] = data.split(bodyEndMarker);
console.log('Orginal Buffer:' + byteArrayStr);
const byteArray = JSON.parse(byteArrayStr.trim());
const buffer = Buffer.from(byteArray); // Convert byte array to Buffer
const ciphertext = buffer.toString('utf8'); // Convert it to string
const updated_output_byte = Array.from(ciphertext).map(char => char.charCodeAt(0));
var output = updated_output_byte + "\n--BODY_END--\n";
console.log('Updated Buffer:' + byteArrayStr);
console.log('Output String'+ciphertext);
fs.writeFileSync(ciphertext, 'utf8');
} catch (e) {
console.log(e);
}
Input:'İÜ' Output:'0�' Output Buffer value: 48 -36 Expected Buffer value: 304 220 log: Orginal Buffer:[48, -36] Updated Buffer:[48, -36] Output String:0� User Script Created File Output: [48, -36] --BODY_END-- 0à There is an error in string-to-byte conversion.