Permalink
Browse files

Try! considers multibyte strings

  • Loading branch information...
1 parent 8db1f13 commit 5881fa8e7f6b5f8339eaffdf3ae4c9c2184d218d @frsyuki frsyuki committed Dec 15, 2013
Showing with 3 additions and 2 deletions.
  1. +3 −2 index.html.erb
View
@@ -59,9 +59,10 @@
return ("0" + e.toString(16)).slice(-2);
}).join(" ");
$("#msgpack-text").text(hex);
- $("#json-bytes").text(text.length.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,') + " bytes");
+ var textLength = encodeURIComponent(text).replace(/%../g,"%").length;
+ $("#json-bytes").text(textLength.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,') + " bytes");
$("#msgpack-bytes").text(msg.length.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,') + " bytes");
- $("#msgpack-percent").text(Math.round(msg.length / text.length * 100).toString() + " %");
+ $("#msgpack-percent").text(Math.round(msg.length / textLength * 100).toString() + " %");
}).keyup();
});
</script>

0 comments on commit 5881fa8

Please sign in to comment.