try ... catch error for convertBinaryText

This commit is contained in:
Divlo 2019-09-15 22:21:02 +02:00
parent 7c2c79041f
commit 8d11d1b804
2 changed files with 20 additions and 13 deletions

View File

@ -227,6 +227,7 @@ function convertCurrency(currency, euroValue) {
// Convertis du texte (encodé en UTF-8) en binaire et l'inverse aussi (source : http://jsfiddle.net/47zwb41o) // Convertis du texte (encodé en UTF-8) en binaire et l'inverse aussi (source : http://jsfiddle.net/47zwb41o)
// UTF-8 vers Binaire // UTF-8 vers Binaire
function utf8ToBin(s) { function utf8ToBin(s) {
try {
s = unescape( encodeURIComponent(s)); s = unescape( encodeURIComponent(s));
var chr, i = 0, l = s.length, out = ''; var chr, i = 0, l = s.length, out = '';
for( ; i < l; i ++ ){ for( ; i < l; i ++ ){
@ -235,15 +236,22 @@ function utf8ToBin(s) {
out += chr; out += chr;
} }
return out; return out;
} catch (error) {
return s;
}
} }
// Binaire vers UTF-8 // Binaire vers UTF-8
function binToUtf8(s){ function binToUtf8(s){
try {
var i = 0, l = s.length, chr, out = ''; var i = 0, l = s.length, chr, out = '';
for( ; i < l; i += 8){ for( ; i < l; i += 8){
chr = parseInt( s.substr(i, 8 ), 2).toString(16); chr = parseInt( s.substr(i, 8 ), 2).toString(16);
out += '%' + ((chr.length % 2 == 0) ? chr : '0' + chr); out += '%' + ((chr.length % 2 == 0) ? chr : '0' + chr);
} }
return decodeURIComponent(out); return decodeURIComponent(out);
} catch (error) {
return s;
}
} }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////

View File

@ -185,7 +185,6 @@ $(function () {
{ {
let binaryTextValue = $('#binaryTextValue').val(); let binaryTextValue = $('#binaryTextValue').val();
let convertIn = $("#convertIn option:selected").text(); let convertIn = $("#convertIn option:selected").text();
let isBinaryValue = isStringBin(binaryTextValue);
if(isEmptyValue(binaryTextValue)) { if(isEmptyValue(binaryTextValue)) {
$('.results').html(emptyMessageError); $('.results').html(emptyMessageError);