[Pkg-javascript-commits] [node-entities] 26/63: handle astral symbols

Wolfgang Borgert debacle at moszumanska.debian.org
Mon Sep 22 08:15:46 UTC 2014


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to branch master
in repository node-entities.

commit df72dd4c99dfb1e5cf21c690822c9bad6a9a96e3
Author: Felix Böhm <me at feedic.com>
Date:   Fri Aug 30 15:08:56 2013 +0200

    handle astral symbols
---
 index.js | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/index.js b/index.js
index b536538..ba80a90 100644
--- a/index.js
+++ b/index.js
@@ -83,10 +83,19 @@ function getStrictReplacer(obj){
 		}
 }
 
-var re_nonUTF8 = /[\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]/g;
+var re_nonASCII = /[^\0-\x7F]/g,
+    re_astralSymbols = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
 
 function nonUTF8Replacer(c){
-	return "&#" + c.charCodeAt(0) + ";";
+	return "&#x" + c.charCodeAt(0).toString(16).toUpperCase() + ";";
+}
+
+function astralReplacer(c){
+	// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
+	var high = c.charCodeAt(0);
+	var low  = c.charCodeAt(1);
+	var codePoint = (high - 0xD800) * 0x400 + low - 0xDC00 + 0x10000;
+	return "&#x" + codePoint.toString(16).toUpperCase() + ";";
 }
 
 function getReverse(obj){
@@ -106,7 +115,8 @@ function getReverse(obj){
 	return function(data){
 		return data
 				.replace(regex, func)
-				.replace(re_nonUTF8, nonUTF8Replacer);
+				.replace(re_astralSymbols, astralReplacer)
+				.replace(re_nonASCII, nonUTF8Replacer);
 	};
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-entities.git



More information about the Pkg-javascript-commits mailing list