Created
May 2, 2012 22:26
-
-
Save FGRibreau/2581006 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Fix the "Could not decode a text frame as UTF-8." bug #socket.io #nodejs #websocket | |
* | |
* Usage: | |
* cleanedString = filterUnicode(maybeHarmfulString); | |
* | |
* Original work-around from SockJS: https://github.com/sockjs/sockjs-node/commit/e0e7113f0f8bd8e5fea25e1eb2a8b1fe1413da2c | |
* Other work-around: https://gist.github.com/2024272 | |
* | |
*/ | |
var escapable = /[\x00-\x1f\ud800-\udfff\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufff0-\uffff]/g; | |
function filterUnicode(quoted){ | |
escapable.lastIndex = 0; | |
if( !escapable.test(quoted)) return quoted; | |
return quoted.replace( escapable, function(a){ | |
return ''; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment